Skip to content

Commit 9fa4986

Browse files
committed
feat: Use multiple loop variables to print index and exponential growth in for-loop
🧠 Logic: - The `for` loop initializes two variables: `i = 0` (incremented by 1 each iteration) and `j = 1` (doubles each time: j = j * 2). - Loop continues while `i <= 10`. - On each iteration, prints: - `i`: linear progression (0 to 10) - `j`: exponential progression (1, 2, 4, 8, ..., 1024) Signed-off-by: Somesh diwan <[email protected]>
1 parent ca1b3d8 commit 9fa4986

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Section8LoopAB/src/ForLoopAB2.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
public class ForLoopAB2
2-
{
3-
public static void main(String[] args)
4-
{
5-
for(int i=0, j=1; i<=10; i++, j=j*2)
6-
{
1+
public class ForLoopAB2 {
2+
public static void main(String[] args) {
3+
for(int i=0, j=1; i<=10; i++, j=j*2) {
74
System.out.println(i);
85
System.out.println(j);
96
}
107
}
11-
}
8+
}

0 commit comments

Comments
 (0)