Loop structures: Difference between revisions
Content added Content deleted
No edit summary |
m (→{{header|Déjà Vu}}: Updates example) |
||
Line 141: | Line 141: | ||
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: |
<lang dejavu>for i range 1 3: |
||
print i # prints 1, 2 and 3</lang> |
!print i # prints 1, 2 and 3</lang> |
||
===While=== |
===While=== |
||
<lang dejavu>while true: |
<lang dejavu>while true: |
||
print "This is the song that never ends..."</lang> |
!print "This is the song that never ends..."</lang> |
||
===Repeat=== |
===Repeat=== |
||
<lang dejavu>repeat 3: |
<lang dejavu>repeat 3: |
||
print "This sentence is printed three times."</lang> |
!print "This sentence is printed three times."</lang> |
||
==[[Factor]]== |
==[[Factor]]== |