🧭 Control Statements in Java / నియంత్రణ వాక్యాలు (Control Statements)
🔹 Definition / నిర్వచనం:
Control statements are used to control the flow of execution of a program based on certain conditions or loops.
Javaలో Control Statements అనేవి program execution (program ఎక్కడి నుండి ఎక్కడికి వెళ్ళాలో) నిర్ణయిస్తాయి.
⚙️ Types of Control Statements / నియంత్రణ వాక్యాల రకాలు
Java has three main types of control statements:
| Type | Telugu Meaning | Used For |
|---|---|---|
| 1. Decision Making Statements | నిర్ణయాత్మక వాక్యాలు | Conditions check చేయడానికి |
| 2. Looping Statements | పునరావృత వాక్యాలు | Code repeatedly execute చేయడానికి |
| 3. Jump Statements | దూకు వాక్యాలు | Control ను ఒక place నుండి మరో place కు మార్చడానికి |
🧩 1. Decision-Making Statements
These statements help Java decide which block of code to execute.
✅ (a) if Statement
Syntax:
Example:
🗣️ Output: Eligible to vote
✅ (b) if-else Statement
Syntax:
Example:
🗣️ Output: Pass
✅ (c) if-else-if Ladder
Used when there are multiple conditions.
🗣️ Output: Grade B
✅ (d) Nested if Statement
An if inside another if.
🗣️ Output: Eligible for donation
✅ (e) switch Statement
Used when you have many possible values for one variable.
🗣️ Output: Wednesday
🔁 2. Looping Statements (Iteration Statements)
Used to execute code multiple times.
| Type | Description |
|---|---|
for loop | When number of iterations known |
while loop | When number of iterations not known |
do-while loop | Executes at least once |
(a) for loop
🗣️ Output:
1
2
3
4
5
(b) while loop
(c) do-while loop
Executes at least once, even if condition is false.
🚀 3. Jump Statements
Used to transfer control from one part to another.
| Statement | Function |
|---|---|
break | Terminates loop or switch |
continue | Skips current iteration |
return | Exits from method |
(a) break Example:
🗣️ Output:
1
2
(b) continue Example:
🗣️ Output:
1
2
4
5
(c) return Example:
🗣️ Output: Before return
🎯 Summary Table
| Type | Statements | Use |
|---|---|---|
| Decision Making | if, if-else, if-else-if, nested if, switch | Based on conditions |
| Looping | for, while, do-while | Repeat code |
| Jump | break, continue, return | Change control flow |