Java Loops and Jumping Statements
1) What is while loop in Java?
A while loop in Java is a control statement used to repeat a block of code as long as a given condition is true. The
condition is checked before executing the loop body, so if the condition is false initially, the loop will not execute
even once.
Syntax:
while (condition) {
// statements to be executed
}
2) What is for loop in Java?
A for loop in Java is used to repeat a block of code a fixed number of times. It is generally used when the number
of iterations is known in advance.
Syntax:
for (initialization; condition; increment/decrement) {
// statements to be executed
}
3) What is do-while loop in Java?
A do-while loop in Java executes a block of code at least once and then repeats it as long as the given condition is
true. The condition is checked after executing the loop body.
Syntax:
do {
// statements to be executed
} while (condition);
4) What are jumping statements?
Jumping statements in Java are used to change the normal flow of execution by transferring control from one part
of the program to another.
The jumping statements in Java are:
• break
• continue
• return
5) Explain break, continue and return statements
Break: Terminates a loop or switch statement immediately.
Continue: Skips the current iteration of a loop and moves to the next iteration.
Return: Terminates a method and optionally returns a value to the calling method.