Java While Loop Basics: Condition-Based Repetition

Day 10 – Learning Java Full Stack Today let's learn about While Loop. The while loop is used when we want to execute a block of code repeatedly as long as a condition is true. Syntax: while (condition) { // loop body } The loop keeps running until the condition becomes false. Example: int a = 1; while (a <= 5) { System.out.println("JAVA"); a++; } Execution Flow: When a = 1 → JAVA When a = 2 → JAVA When a = 3 → JAVA When a = 4 → JAVA When a = 5 → JAVA When a = 6 → Condition becomes false → Loop terminates Key takeaway: A while loop is condition-based repetition. If the condition never becomes false, it can lead to an infinite loop — so updating the variable is very important. More learning updates coming soon #Java #JavaFullStack #WhileLoop #ControlStatements #LearningInPublic #CoreJava

To view or add a comment, sign in

Explore content categories