Loops/For with a specified step: Difference between revisions
Content added Content deleted
(Bait solution) |
|||
Line 1,546: | Line 1,546: | ||
Icon and Unicon accomplish loop stepping through the use of a generator, the ternary operator to-by, and the every clause which forces a generator to consume all of its results. |
Icon and Unicon accomplish loop stepping through the use of a generator, the ternary operator to-by, and the every clause which forces a generator to consume all of its results. |
||
Because to-by is an operator it has precedence (just higher than assignments) and associativity (left) and can be combined with other operators. |
Because to-by is an operator it has precedence (just higher than assignments) and associativity (left) and can be combined with other operators. |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="pascal"> |
||
every 1 to 10 by 2 # the simplest case that satisfies the task, step by 2 |
every 1 to 10 by 2 # the simplest case that satisfies the task, step by 2 |
||
every 1 to 10 # no |
every 1 to 10 # no by, step is 1 by default |
||
every EXPR1 to EXPR2 by EXPR3 do EXPR4 # general case - EXPRn can be complete expressions including other generators such as to-by, every's do is optional |
every EXPR1 to EXPR2 by EXPR3 do EXPR4 # general case - EXPRn can be complete expressions including other generators such as to-by, every's do is optional |
||
steps := [2,3,5,7] # a list |
steps := [2,3,5,7] # a list |