Java control statements are used to control the flow of execution in a program. They enable decision-making, looping, and branching, allowing developers to create dynamic and flexible programs.
Types of Java Control Statements
1. Decision-Making Statements
The if statement is a powerful decision-making statement and is used to control the flow of execution of statements. It is basically a two-way Decision statement and is used in conjunction with an expression.
if(test expression)
2. Looping Statements
A computer is suited to perform repetitive operations. It can do it repeatedly for 10,100 or even 10,000 times. Every computer language must have features that instruct a computer to perform such repetitive tasks.
for (initialization; condition; increment/decrement) {
// Code to be executed
}
Java Control Statements – Interview Questions
Q 1: What are control statements in Java?
Ans: They control the flow of program execution.
Q 2: How many types of control statements exist?
Ans: Selection, Looping, and Jump statements.
Q 3: Give examples of looping statements.
Ans: for, while, do-while.
Q 4: What are jump statements?
Ans: break, continue, and return.
Q 5: Why are control statements important?
Ans: They help in decision-making and looping.