Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Control statements

Rating
-
Sold
-
Pages
16
Uploaded on
14-10-2024
Written in
2024/2025

Control statements used in java programming

Institution
Course

Content preview

6/10/2021 Control Flow in Java - Javatpoint



Control Flow in Java
Java compiler executes the java code from top to bottom. The statements 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.

Java provides three types of control flow statements.


1. Decision Making statements

2. Loop statements

3. Jump statements


Decision-Making statements:

Decision-making statements evaluate the Boolean expression and control the program flow
depending upon the condition result. There are two types of decision-making statements in java,
I.e., If statement and switch statement.


If Statement:

In Java, the "if" statement is used to evaluate a condition. The control of the program is diverted
depending upon the condition result that is a Boolean value, either true or false. In java, there are
four types of if-statements given below.

1. if statement

2. if-else statement

3. else-if statement

4. Nested if-statement


Let's understand the if-statements one by one.

1. if statement:






https://www.javatpoint.com/control-flow-in-java 2/20

,6/10/2021 Control Flow in Java - Javatpoint

Triggers in SQL (Hindi)




This is the most basic statement among all control flow statements in java. It evaluates a Boolean
expression and enables the program to enter a block of code if the expression evaluates to true.

Syntax of if statement is given below.


if(<condition>) {

//block of code

}



Consider the following example in which we have used the if statement in the java code.



public class Student {

public static void main(String[] args) {

int x = 10;

int y = 12;

if(x+y > 20) {

System.out.println("x + y is greater than 20");

}

}




}


Output:


x + y is greater than 20 ⇧

https://www.javatpoint.com/control-flow-in-java 3/20

, 6/10/2021 Control Flow in Java - Javatpoint

2. if-else statement

The if-else statement is an extension to the if-statement, which uses another block of code, I.e.,
else block. The else block is executed if the condition of the if-block is evaluated as false.

Consider the following example.




public class Student {

public static void main(String[] args) {

int x = 10;

int y = 12;

if(x+y < 10) {

System.out.println("x + y is less than 10");

} else {

System.out.println("x + y is greater than 20");

}

}


Output:


x + y is greater than 20




3. lse-if statement

The else-if statement contains the if-statement followed by multiple else-if statements. In other
words, we can say that it is the chain of if-else statements that create a decision tree where the
program may enter any block of code. We can also define an else statement at the end of the
chain.

Consider the following example.


https://www.javatpoint.com/control-flow-in-java 4/20

Written for

Institution
Course

Document information

Uploaded on
October 14, 2024
Number of pages
16
Written in
2024/2025
Type
Class notes
Professor(s)
Pankaj
Contains
All classes

Subjects

$8.79
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
khushisharma8

Get to know the seller

Seller avatar
khushisharma8 Govt. Polytechnic hamirpur
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
6
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions