[go: up one dir, main page]

0% found this document useful (0 votes)
5 views12 pages

Control Statement

The document explains control flow statements in Java, which dictate the order of code execution. It categorizes these statements into decision-making, loop, and jump statements, detailing their types and functionalities. Key components include if statements, switch statements, various loops, and the use of break and continue statements.

Uploaded by

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

Control Statement

The document explains control flow statements in Java, which dictate the order of code execution. It categorizes these statements into decision-making, loop, and jump statements, detailing their types and functionalities. Key components include if statements, switch statements, various loops, and the use of break and continue statements.

Uploaded by

ml4033676
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Control Statement

Control Statement

Java compiler executes the code from top to bottom.


The statements in the code are executed according
to the order in which they appear. However, Java
provides statements that can be used to control the
flow of Java code. Such statements are called control
flow statements. It is one of the fundamental features
of Java, which provides a smooth flow of program.
Types
1. Decision Making statements
○ if statements
○ switch statement
2. Loop statements
○ do while loop
○ while loop
○ for loop
○ for-each loop
3. Jump statements
○ break statement
○ continue statement
Decision-Making statements:

As the name suggests, decision-making statements decide


which statement to execute and when. Decision-making
statements evaluate the Boolean expression and control the
program flow depending upon the result of the condition
provided. There are two types of decision-making statements in
Java, i.e., If statement and switch statement.
Types
1. Simple if statement
2. if-else statement
3. if-else-if ladder
4. Nested if-statement
Switch Statement:

In Java, Switch statements are similar to if-else-if statements.


The switch statement contains multiple blocks of code called
cases and a single case is executed based on the variable
which is being switched. The switch statement is easier to
use instead of if-else-if statements. It also enhances the
readability of the program.
Loop Statements
In programming, sometimes we need to execute the
block of code repeatedly while some condition
evaluates to true. However, loop statements are used
to execute the set of instructions in a repeated order.
The execution of the set of instructions depends
upon a particular condition.
TYPES:
1. for loop
2. while loop
3. do-while loop
While Loop
The while loop is also used to iterate over the number of
statements multiple times. However, if we don't know
the number of iterations in advance, it is recommended
to use a while loop. Unlike for loop, the initialization and
increment/decrement doesn't take place inside the
loop statement in while loop.
Do While Loop
The do-while loop checks the condition at the
end of the loop after executing the loop
statements. When the number of iteration is
not known and we have to execute the loop
at least once, we can use do-while loop.
Jumping Statement

break
Continue.

break
As the name suggests, the break statement is used to break the current
flow of the program and transfer the control to the next statement outside
a loop or switch statement. However, it breaks only the inner loop in the
case of the nested loop.
continue

Unlike break statement, the continue statement doesn't


break the loop, whereas, it skips the specific part of the loop
and jumps to the next iteration of the loop immediately.

You might also like