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

Using the ``every'' construct in Icon

Tech Computer Center logo

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 );
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
See also: A tutorial for the Icon programming language
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
Home: About New Mexico Tech

John Shipman,
Last updated: 1996/01/06 21:12:57 UT
QR two-dimensional bar code