We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Simple WHILE

Hi all,

i'm not able to realize a simple for N times loop in VOLT. Has far as i can see there is no WHILE statement and FOR works only with arrays.

Currently i'm using array_fill from the controller to pass an array of N NULL elements to the template to iterate over it but i downvote for this approach. I've also tried something like

{% FOR i in 5 %}

but PHP, obviously, reported: PHP Warning: Invalid argument supplied for foreach()



8.1k

See define of foreach in PHP :)



20.3k

I suppose to know what foreach means. VOLT FOR statement is equal to PHP FOREACH. But how to have a simple loop in VOLT? Ex: Print 5 times the letter 'a' in VOLT.



1.2k
Accepted
answer

you mean like this ? {% for a in 0..10 %} {{ a }} {% endfor %}



20.3k

thanks linbob! This is exactly what i meant! Thanks very much!

In the documentation the only reference for this is in Operators=>Range. A clear example of the usage may help readers to find out this feature. Regards