Cloudbook: C

  1. Home
  2. Control
  3. Foreach
  4. § 2 exercise →
Foreach

The block of code controlled by the foreach statement is run once on each element of the list. A copy of the (scalar) value at each location of the list, in turn, is placed into the named scalar in the statement, in this case $code, and the block run with this assignment. This is repeated for each element of the list, in turn, and then the code moves on the the following statements. If the list is empty, no problem, the block of code is never run.