Java Control Statements if-else Loops

📘 Day 6 of Java Learning Series 🔹 Control Statements in Java (if-else, loops) Control statements help us control the flow of execution in a program. They allow decision-making and repetition of tasks. 🔸 1. if-else Statement (Decision Making) Used when we want to execute code based on a condition. 💡 Example: int age = 18; if (age >= 18) { System.out.println("You can vote"); } else { System.out.println("You cannot vote"); } 🔸 2. Loops (Repetition) Loops help us execute a block of code multiple times. 👉 for loop (when number of iterations is known) for (int i = 1; i <= 5; i++) { System.out.println(i); } 👉 while loop (runs while condition is true) int i = 1; while (i <= 5) { System.out.println(i); i++; } ✅ Key Takeaways: ✔ if-else → decision making ✔ loops → repetition ✔ for loop → fixed iterations ✔ while loop → condition-based execution 💬 Which loop do you use more – for or while? 👉 Follow me for more Java content 🚀 #Java #Programming #100DaysOfCode #Developers #Learning #CoreJava

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories