Java_Loops_Manual
Java_Loops_Manual
1. Introduction to Loops
In programming, loops are used to execute a block of code multiple times until a specified condition is met.
Java provides three types of loops:
- For Loop
- While Loop
- Do-While Loop
Syntax:
Syntax:
while(condition) {
// Code to execute
}
Syntax:
while(condition) {
// Code to execute
}
3. Nested Loops
A loop inside another loop is called a nested loop.
The break statement is used to exit a loop prematurely when a specific condition is met.
import java.util.Scanner;
int sum = 0;
scanner.close();
}
}