Loops/For with a specified step: Difference between revisions

m
(Bait solution)
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.
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="iconpascal">
every 1 to 10 by 2 # the simplest case that satisfies the task, step by 2
 
every 1 to 10 # no toby, step is by 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
steps := [2,3,5,7] # a list
57

edits