Loops in Java
Loops in Java
➤ Introduction
Loops in Java allow a set of instructions to be executed repeatedly until a
certain condition is met. Java supports three main types of loops:
• for loop
• while loop
• do-while loop
1. for Loop
Syntax:
java
CopyEdit
for (initialization; condition; update) {
// code to repeat
}
2. while Loop
Syntax:
java
CopyEdit
while (condition) {
// code to repeat
}
3. do-while Loop
The do-while loop runs at least once, even if the condition is false, because the
condition is checked after the first execution.
Syntax:
java
CopyEdit
do {
// code to repeat
} while (condition);
Even though the condition is false, the message still prints once.
Condition
Before loop body Before loop body After loop body
checked?
Runs at least
No No Yes
once?
Prepared By:
Annexa Academics – Grade 9 ICSE Java Programming
No Copyright Claimed
This material has been created for educational purposes and is intended for
free public use.
The content in this document is released into the public domain by the author
and contributors.
You are free to copy, share, modify, distribute, or use this material in any form,
with or without attribution.
This resource was created with the support of AI tools and compiled by Annexa
Academics for the benefit of students and educators.
****************************************************************