A loop is a programming tool that is used to repeat a set of instructions.
THERE ARE 3TYPES OF LOOPS:
for Iterates over values and expressions
while Iterates over a condition
do...while Iterates over a condition
- FOR LOOP:
For Loops can execute a block of code a number of times.
For Loops are fundamental for tasks like performing an action multiple times.
SYNATX:
for (initialization; condition; increment/decrement) {
// Code to execute
}
2.WHILE LOOP:
Some loops execute a block of code as long as a specified condition is true.
SYNTAX:
while (condition) {
// code block to be executed
}
3.DO WHILE LOOP:
while is similar to while loop except it execute the code block at least before checking the condition.
SYNTAX:
do {
// Code to execute
} while (condition);
Top comments (0)