Looping statements in c
🔁 Looping Statements in C
Loops allow repeating code multiple times until a condition is satisfied.
1️⃣ for Loop
📘 Full Definition
The for loop is used when the number of iterations is known in advance.
It combines initialization, condition, and increment/decrement in a single line.
⚡ Shortcut: Best for fixed repetitions.
🔹 Syntax:
for(initialization; condition; update) {
// code to execute
}
2️⃣ while Loop
📘 Full Definition
The while loop is used when the number of iterations is not known in advance.
It keeps executing as long as the condition is true.
⚡ Shortcut: Repeat while condition is true.
🔹 Syntax:
while(condition) {
// code to execute
}
3️⃣ do-while Loop
📘 Full Definition
The do-while loop executes the block at least once, and then continues
as long as the condition is true.
⚡ Shortcut: Executes at least once.
🔹 Syntax:
do {
// code to execute
} while(condition);
Comments
Post a Comment