## Doing simple arithmetic in Icon |

Here is a simple Icon program that finds the sum of the numbers from one to five:

procedure main() local n, sum # Declare two local variables sum := 0; # Set the sum to zero every n := 1 to 5 do # For n equal to 1, 2, 3, 4, 5 ... sum := sum + n; # ...add n to the sum write ( "The sum of all numbers from 1 to 5 is ", sum ); endSeveral new features are introduced in this program:

- The ``
`local`

'' declaration is used to define all variables. The type of a variable is determined by its usage, not by its declaration. - The construct ``
`every`

'' is used to repeat statement*e1*do*e2**e2*some number of times determined by the expression*e1*. - The construct ``
*variable*:=*expression*'' computes the value of an expression and stores it in a variable.

Site map

To report a problem:

Send mail to the

John Shipman, john@nmt.edu
Last updated: 1996/01/06 21:12:57 UTURL: http://www.nmt.edu/tcc/help/lang/icon/hellomath.html |