REPEAT/FOR
REPEAT
/FOR
allows you to repeat a given block of code <int>
times.
Also supports an optional parameter for a new variable that keeps count
of the current iteration, which is zero based.
Syntax
REPEAT <OPTIONAL: count declaration>,<int>
<codeBlock>
- Basic
- Counter
DucklingScript
REPEAT 3
PRINT Hello World
FOR 3
PRINT Goodbye!
Output
Hello World
Hello World
Hello World
Goodbye!
Goodbye!
Goodbye!
DucklingScript
REPEAT n,3
$PRINT "I like the number "+n+"!"
FOR n,3
$PRINT "I don't like the number "+(n+3)+" >:("
Output
I like the number 0!
I like the number 1!
I like the number 2!
I don't like the number 3 >:(
I don't like the number 4 >:(
I don't like the number 5 >:(
warning
Please note that there is a limit to for loops; for loops will eventually error if they run too many times. This can be avoided however by using inner for loops, but that is not recommended.