Skip to content

Commit 3e240fa

Browse files
committed
feat: Demonstrate basic while loop with counter increment
✅ Logic: - Runs loop while counter < 10, printing the counter value - Increments counter to avoid infinite loop - Includes commented-out infinite loop example for demonstration. Signed-off-by: Somesh diwan <[email protected]>
1 parent 9860b79 commit 3e240fa

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
public class TheWhileLoop
2-
{
3-
public static void main(String[] args)
4-
{
1+
public class TheWhileLoop {
2+
public static void main(String[] args) {
53
int counter = 0;
64

75
while (counter < 10 ) //while counter is less than 10...
@@ -11,11 +9,11 @@ public static void main(String[] args)
119
counter++; //Variable update is crucial in these types of loops.
1210
}
1311
/*
14-
while (counter >= 0) //uncomment to run this example
12+
while (counter >= 0) //un-comment to run this example
1513
{
1614
System.out.println("counter value is " + counter);
1715
System.out.println("I am stuck in an endless loop!");
1816
}
1917
*/
2018
}
21-
}
19+
}

0 commit comments

Comments
 (0)