0% found this document useful (0 votes)
8 views2 pages

Control Statements Assignment

Control statements in Java manage the flow of execution in a program, allowing for decision making, looping, and jumping. The main types include decision making statements (if, if-else, switch), looping statements (for, while, do-while, for-each), and jumping statements (break, continue, return). These statements are essential for creating functional and efficient Java programs.

Uploaded by

shalinsunil1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Control Statements Assignment

Control statements in Java manage the flow of execution in a program, allowing for decision making, looping, and jumping. The main types include decision making statements (if, if-else, switch), looping statements (for, while, do-while, for-each), and jumping statements (break, continue, return). These statements are essential for creating functional and efficient Java programs.

Uploaded by

shalinsunil1
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ASSIGNMENT ON CONTROL STATEMENTS IN JAVA

What is Control Statement?

Control statements are used to control the flow of execution in a program.


Normally, Java executes code line by line from top to bottom.
But sometimes we need to repeat actions, make decisions, or skip certain parts.
Control statements help us manage this flow of the program.

Types of Control Statements:

1. Decision Making Statements – if, if-else, switch


2. Looping Statements – for, while, do-while, for-each
3. Jumping Statements – break, continue, return

Looping Control Statements with Examples

1. For Loop
Used when we know how many times the loop should run.

Example:

for(int i = 1; i <= 5; i++) {


[Link](i);
}

Output:
12345

2. While Loop
Used when the number of iterations depends on a condition.

Example:

int i = 1;
while(i <= 5) {
[Link](i);
i++;
}

Output:
12345

3. Do-While Loop
This loop executes at least one time even if the condition is false.

Example:

int i = 1;
do {
[Link](i);
i++;
} while(i <= 5);

Output:
12345

4. For-Each Loop (Enhanced For Loop)


Used mainly for arrays and collections.

Example:

int arr[] = {10, 20, 30, 40};


for(int num : arr) {
[Link](num);
}

Output:
10 20 30 40

Conclusion:

Control statements are very important in Java programming.


They help us repeat tasks, make decisions, and control how our program runs.
Without control statements, writing real-world programs would not be possible.

You might also like