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

How expressions work in Icon

Tech Computer Center logo

There are two important properties of Icon expressions:

  1. Icon has no statements, just expressions.
  2. In general, an expression is a sequence of operations that may produce zero or more results.

In general, Icon loops take the form ``every e1 do e2'' where e1 and e2 can be any expression. If e1 produces no results, e2 is never evaluated. If it produces 19 results, e2 is evaluated 19 times, and so on.

Let's take another look at the loop in the simple arithmetic program:

      every  n := 1 to 5  do   # For n equal to 1, 2, 3, 4, 5 ...
        sum  :=  sum + n;      # ...add n to the sum
In this case, the expression ``n:=1 to 5'' produces five results, so the loop is executed five times. The expression ``1 to 5'' produces the values from 1 to 5 in sequence.
Next: Using the ``every'' construct in Icon
See also: A tutorial for the Icon programming language
Previous: Doing simple arithmetic in Icon
Site map
Index: Keyword index to help pages
Help: New Mexico Tech Computer Center: Help System
TCC Publications
Home: About New Mexico Tech

John Shipman, john@nmt.edu

Last updated: 1996/01/06 21:12:57 UT
URL: http://www.nmt.edu/tcc/help/lang/icon/howexpr.html