Professional Documents
Culture Documents
For Loop
For Loop
First step: In for loop, initialization happens first and only one time, which
means that the initialization part of for loop only executes once.
Third step: After every execution of for loop’s body, the increment/decrement
part of for loop executes that updates the loop counter.
Fourth step: After third step, the control jumps to second step and condition
is re-evaluated.
Example:
Output:
Activity 1: For Loop Syntax. Fill in the blanks to make the block of code work.
Save the file as LastnameFirstnameForLoop.pdf.
1.
System.out.print("*");
System.out.println("");
}
Expected Output:
**
***
****
*****
2.
(5)_________("*");
System.out.println("");
Expected Output:
*****
****
***
**
Activity 2. The previous activity shows the generation of two star pyramids. In
this activity, create two pyramids consisting of numbers with the use of For
Loop. Place both codes in one file.
Expected Output:
12
123
1234
12345
Expected Output:
12345
1234
123
12