@for
You can use regular for loops to iterate over an array or a range of numbers.
This is a basic for loop that you can use. It has a declaration, condition and post statement. for <declaration>; <condition>; <post>. They are all optional. Example:
textwire
{{ names = ["Ann", "Serhii"] }}
@for(i = 0; i < names.len(); i++)
<p>{{ names[i] }}</p>
@else
<p>No names</p>
@endRead more about loops in the Loops guide.
Example with @continueif
This example renders a list of names and skips Serhii with @continueif:
textwire
{{ names = ["Ann", "Serhii", "Vladimir"] }}
<ul>
@for(i = 0; i < names.len(); i++)
@continueif(names[i] == "Serhii")
<li>{{ names[i] }}</li>
@end
</ul>Important Notes
- Extends parent scope. For loop extends parent scope, which means that you can manipulate variables defined outside of the loop. For example, you can define a variable outside of the loop and increment it inside the loop.
loopobject.@forloops provide aloopobject with iteration metadata. Theloop.lastproperty is only available in@eachloops. Read more about Loop Variables.
