Loop structures: Difference between revisions

Content added Content deleted
Line 212: Line 212:
===For===
===For===
Déjà Vu has a for-loop protocol, so you can write your own iterators. The most commonly used iterators are <code>in</code> and <code>range</code>. The first iterates over a list, the second takes two arguments and goes from the first to the second, like a classic for-loop.
Déjà Vu has a for-loop protocol, so you can write your own iterators. The most commonly used iterators are <code>in</code> and <code>range</code>. The first iterates over a list, the second takes two arguments and goes from the first to the second, like a classic for-loop.
<lang dejavu>for i range 1 3:
<syntaxhighlight lang="dejavu">
for i range 1 3:
!print i # prints 1, 2 and 3</lang>
!print i # prints 1, 2 and 3
</syntaxhighlight>
===While===
===While===
<lang dejavu>while true:
<syntaxhighlight lang="dejavu">
while true:
!print "This is the song that never ends..."</lang>
!print "This is the song that never ends..."
</syntaxhighlight>
===Repeat===
===Repeat===
<lang dejavu>repeat 3:
<syntaxhighlight lang="dejavu">
repeat 3:
!print "This sentence is printed three times."</lang>
!print "This sentence is printed three times."
</syntaxhighlight>


==[[Factor]]==
==[[Factor]]==