Basic HTML version of Foils prepared October 30 1999

Foil 7 "For" Loops

From Short Introduction to Kids on Basic Programming Concepts in Java Sonia Kovalesky festival workshop (High School Girls) -- October 23 1999. by Nancy McCracken


1 A loop statement tells the computer to execute a set of instructions many times, and is controlled by the loop variable.
2 int sum, num;
3 num = 8;
4 sum = 0;
5 for ( int i = 0; i < num; i++ )
6 {
7 sum = sum + i;
8 }
9 repeat loop 8 times and
10 add 1 to i each time
11 The body of the loop is repeated. Values of i each time around the loop:
12 i is 0
13 i is 1
14 i is 2
15 . . .
16 i is 7
17 What is the value of sum at the end?

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Oct 30 1999