Control Statements in Java
In Java, control statements are used to alter the flow of execution in a program. They help in decision-making, looping, and branching. Here's a complete overview:
✅ Types of Control Statements in Java
Java control statements are mainly classified into:
-
Decision-Making Statements
-
Looping (Iteration) Statements
-
Branching Statements
πΉ 1. Decision-Making Statements
a) if Statement
b) if-else Statement
c) if-else-if Ladder
d) switch Statement
πΉ 2. Looping (Iteration) Statements
a) for Loop
b) while Loop
c) do-while Loop
d) Enhanced for-each Loop (used with arrays/collections)
πΉ 3. Branching Statements
a) break
Used to exit a loop or switch early.
b) continue
Skips the current iteration and goes to the next.
c) return
Exits from the method and optionally returns a value.
π Summary Table
| Category | Statement | Purpose |
|---|---|---|
| Decision | if, else, switch | For making choices |
| Looping | for, while, do-while, for-each | For repeating tasks |
| Branching | break, continue, return | To alter loop/method flow |
Comments
Post a Comment