Basic HTML version of Foils prepared June 5 99

Foil 17 For Loops (slide from Java Academy)

From Java Language in the Computer Science Curriculum ADMI Tutorial Duluth Minnesota -- June 3 99. by Geoffrey C. Fox


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



© 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 Jun 5 1999