for. Loop with specified number of repetitions


for repeatedly implements the body of the loop, going through counter's values from initial to final. Every repetition automatically increments the counter's value by one.

Counter is the name of variable used as the loop's counter.

From and to, respectively, are initial and final values of the counter-mathematical expressions specifying the scope of values assigned to the counter. If final value is less than the initial, the body of the loop will not be implemented at all.

Delimiter is string or code to be implemented before every non-empty body, except the first.

Important notice: since the names of the counters can be repeated, we recommend declaring them as local variables of the method which uses
for loop.

You can force finish the loop using
break operator or finish current step and go to next one using continue operator. [3.2.2]

   <a href="/news/archive.html?week=$week">News for week $week</a>
<br />]

The example outputs references to weeks 1-4. After every string, it puts the newline tag.

Copyright © 1997–2021 Art. Lebedev Studio | Last updated: 20.09.2007