Computer Lesson 10 Class9 Loop
Computer Lesson 10 Class9 Loop
for loop
Syntax:
for (int i=1 ; i<=5 ; i++) for (int i=2 ; i<11; i=i+2)
{ {
System.out.println( i ); System.out.println( i );
} }
Output: Output:
1 2
2 4
3 6
4 8
5 10
Example 3: Example 4:
for (int i=9 ; i>=1; i=i-2) for (int i=5 ; i>1; i--)
{ {
System.out.println( i ); System.out.println( i );
} }
Output: Output:
9 5
7 4
5 3
3 2
1
Example 5: Example 6:
for (int i=1 ; i<5; i++) for (int i=7 ; i>=0; i=i-3)
{ {
} }
Output: Output:
1 6
4 3
9 0
16