0% found this document useful (0 votes)
8 views2 pages

Lesson 3 Java Revision Sheet - Loops Comparison (For, While, Do-While)

This document provides a comparison of the three loop types in Java: for, while, and do-while, highlighting their best use cases and syntax. It includes examples for each loop type and a comparison table detailing features such as entry control and whether they run at least once. Additionally, it suggests an exercise to practice printing even numbers from 1 to 20 using all three loop types.

Uploaded by

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

Lesson 3 Java Revision Sheet - Loops Comparison (For, While, Do-While)

This document provides a comparison of the three loop types in Java: for, while, and do-while, highlighting their best use cases and syntax. It includes examples for each loop type and a comparison table detailing features such as entry control and whether they run at least once. Additionally, it suggests an exercise to practice printing even numbers from 1 to 20 using all three loop types.

Uploaded by

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

Java Revision Sheet – Loops Comparison (for, while, do-while)

Description:
This revision handout compares all three loop types in Java. It's useful for students revising
for tests or understanding when to use which loop based on real examples.

🔁 Why Use Loops?

Loops help us execute a block of code repeatedly, either a specific number of times or until a
condition is met.

🔄 Types of Loops in Java

Loop Type Best Used When… Syntax Overview


for loop Number of iterations is known for (init; condition; update) { }
while loop Iteration until condition is true while (condition) { }
do-while Execute at least once, then check do { } while (condition);

🔧 1. for Loop Example


java
CopyEdit
for (int i = 1; i <= 5; i++) {
System.out.println("Count: " + i);
}

🔄 2. while Loop Example


java
CopyEdit
int i = 1;
while (i <= 5) {
System.out.println("Count: " + i);
i++;
}

🔂 3. do-while Loop Example


java
CopyEdit
int i = 1;
do {
System.out.println("Count: " + i);
i++;
} while (i <= 5);
⚖️Comparison Table

Feature for while do-while


Entry Control? Yes Yes No (Exit control)
Runs at least once? No No Yes
Common Use Counting loops User input / condition-based Menus, retries

🧠 Exercise: Print Even Numbers from 1 to 20 Using All Loops

 Try using for, while, and do-while separately.


 Use if (i % 2 == 0) condition inside the loop.

You might also like