:
COUNTER = 0.
PERFORM PRINT-NUMBER 100 TMES.
:
PRINT-NUMBER.
DISPLAY COUNTER.
ADD 1 TO COUNTER.
for (multiple = 5; multiple <= 95; multiple += 5)
{printf(“%3d”, multiple);
}
printf(“\n”);
Will produce the following output
5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95
The three statements enclosed in parenthesis represent the following
multiple = 5 - initializes the loop control variable to 5
multiple <= 95 compares the loop control variable to the stop value 95. As long as the expression evaluates to True the loop will continue
multiple += 5 increments the loop control value by 5
The “%3d” constant used in the print statement ensures that each integer will be
allocated 3 spaces resulting in a space following the number
With C the loop condition and step statement are NOT restricted to using the
variable used in the initialize statement.
for (int i = 1, j = 100; i < 100; i = i+1, j = j-1)
{
System.out.println(i + j);
}
What output do you think the preceding for loop will produce?