Next / Previous / Index / ITC Help System / Publications / Site map / NM Tech homepage

# Using the ``every'' construct in Icon

The general form of the ``every'' loop in Icon is:

`    every e1 do e2`
This means, every time expression e1 produces a result, evaluate expression e2.

The ```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 );
end```
The construct ```v +:= e`'' means: compute the value of expression e and add it to the current value of variable v.
Next: Using procedures in Icon
Previous: How expressions work in Icon
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Information Technology and Communications: Help System
ITC Publications
To report a problem: File a ticket
Send mail to the User consultant on duty or call them at 575-835-5437