Looping in Other Languages

COBOL 74

:
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


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.
 


Java

 

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?