Posts

Showing posts with the label For Loop

Control Flow in Java

Image
Chapter 5: Control Flow in Java Chapter 5: Control Flow in Java Control flow in Java refers to the order in which instructions, statements, and function calls are executed or evaluated. Java provides several mechanisms to control the flow of execution through the program: 🧩 1. Conditional Statements Conditional statements execute different blocks of code based on certain conditions. 🔸 if Statement int number = 10; if (number > 5) { System.out.println("Number is greater than 5"); } 🔸 if-else Statement int number = 4; if (number > 5) { System.out.println("Greater than 5"); } else { System.out.println("Less than or equal to 5"); } 🔸 if-else-if Ladder int score = 85; if (score >= 90) { System.out.println("Grade A"); } else if (score >= 80) { System.out.println("Grade B"); } else { System.out.println("Grade C"); } 🧩 2. sw...