Control Statements in Java: if-else, switch, Loops

🚀 Day 3 of My Java Learning Journey – Control Statements in Java Today, I learned how programs make decisions and repeat tasks using Control Statements in Java. These are essential for building logic in real-world applications. 🔹 Types of Control Statements: ➤ 1. if-else Statement Used for decision making 👉 Executes code based on conditions if (x > 10) { System.out.println("Greater than 10"); } else { System.out.println("Less than or equal to 10"); } ➤ 2. switch Statement Used when we have multiple choices 👉 Cleaner alternative to multiple if-else switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; default: System.out.println("Invalid day"); } ➤ 3. Loops (Repetition Statements) Used to execute code multiple times ✔ for loop – when number of iterations is known ✔ while loop – when condition is checked before execution ✔ do-while loop – executes at least once for(int i = 1; i <= 5; i++) { System.out.println(i); } 💡 Key Learning: Control statements help in decision-making and repeating tasks, making programs smarter and more dynamic. 📌 Practiced writing programs using if-else, switch, and loops to strengthen my logic-building skills. #Java #Programming #CodingJourney #LearningJava #ControlStatements #100DaysOfCode #Developers 🚀

To view or add a comment, sign in

Explore content categories