Loop structures: Difference between revisions
Content added Content deleted
(→Dao) |
|||
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 |
<syntaxhighlight lang="dejavu"> |
||
for i range 1 3: |
|||
!print i # prints 1, 2 and 3 |
!print i # prints 1, 2 and 3 |
||
</syntaxhighlight> |
|||
===While=== |
===While=== |
||
<lang |
<syntaxhighlight lang="dejavu"> |
||
while true: |
|||
!print "This is the song that never ends..." |
!print "This is the song that never ends..." |
||
</syntaxhighlight> |
|||
===Repeat=== |
===Repeat=== |
||
<lang |
<syntaxhighlight lang="dejavu"> |
||
repeat 3: |
|||
!print "This sentence is printed three times." |
!print "This sentence is printed three times." |
||
</syntaxhighlight> |
|||
==[[Factor]]== |
==[[Factor]]== |