Using the ``every'' construct in Icon
The general form of the ``every'' loop in Icon is:
every e1 do e2This means, every time expression e1 produces a result, evaluate expression e2.
do e2'' part is optional.
The expression ``
every e1'' means: compute every result
of e1 in sequence, discarding each one.
We can rewrite the simple arithmetic program this way:
procedure main() local sum # Declare a variable for the sum sum := 0; # Set the sum to zero every sum +:= 1 to 5; write ( "The sum of all numbers from 1 to 5 is ", sum ); endThe construct ``
v +:= e'' means: compute the value of expression e and add it to the current value of variable v.
John Shipman, email@example.com
Last updated: 1996/01/06 21:12:57 UT