Control Statements in Java - SATISH THAWAN

Breaking

Breaking

Featured

Thursday, 16 October 2025

Control Statements in Java

 

🧭 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:

TypeTelugu MeaningUsed 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:

if (condition) { // code executes only if condition is true }

Example:

int age = 20; if (age >= 18) { System.out.println("Eligible to vote"); }

🗣️ Output: Eligible to vote


✅ (b) if-else Statement

Syntax:

if (condition) { // true block } else { // false block }

Example:

int marks = 40; if (marks >= 35) { System.out.println("Pass"); } else { System.out.println("Fail"); }

🗣️ Output: Pass


✅ (c) if-else-if Ladder

Used when there are multiple conditions.

int marks = 75; if (marks >= 90) { System.out.println("Grade A"); } else if (marks >= 75) { System.out.println("Grade B"); } else { System.out.println("Grade C"); }

🗣️ Output: Grade B


✅ (d) Nested if Statement

An if inside another if.

int age = 20; int weight = 60; if (age >= 18) { if (weight >= 50) { System.out.println("Eligible for donation"); } }

🗣️ Output: Eligible for donation


✅ (e) switch Statement

Used when you have many possible values for one variable.

int day = 3; switch(day) { case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; default: System.out.println("Invalid day"); }

🗣️ Output: Wednesday


🔁 2. Looping Statements (Iteration Statements)

Used to execute code multiple times.

TypeDescription
for loopWhen number of iterations known
while loopWhen number of iterations not known
do-while loopExecutes at least once

(a) for loop

for (int i = 1; i <= 5; i++) { System.out.println(i); }

🗣️ Output:
1
2
3
4
5


(b) while loop

int i = 1; while (i <= 5) { System.out.println(i); i++; }

(c) do-while loop

Executes at least once, even if condition is false.

int i = 1; do { System.out.println(i); i++; } while (i <= 5);

🚀 3. Jump Statements

Used to transfer control from one part to another.

StatementFunction
breakTerminates loop or switch
continueSkips current iteration
returnExits from method

(a) break Example:

for (int i = 1; i <= 5; i++) { if (i == 3) break; System.out.println(i); }

🗣️ Output:
1
2


(b) continue Example:

for (int i = 1; i <= 5; i++) { if (i == 3) continue; System.out.println(i); }

🗣️ Output:
1
2
4
5


(c) return Example:

public static void main(String[] args) { System.out.println("Before return"); return; // Code after return won't execute }

🗣️ Output: Before return


🎯 Summary Table

TypeStatementsUse
Decision Makingif, if-else, if-else-if, nested if, switchBased on conditions
Loopingfor, while, do-whileRepeat code
Jumpbreak, continue, returnChange control flow

Food