Loops in C

πŸ“˜ C πŸ‘ 62 views πŸ“… Dec 22, 2025
⏱ Estimated reading time: 1 min

Loops are used to execute a block of code repeatedly as long as a specified condition is true.


Types of Loops in C

  1. for loop

  2. while loop

  3. do–while loop


1. for Loop

Used when the number of iterations is known.

Syntax

for (initialization; condition; increment/decrement) { statements; }

Example

for (int i = 1; i <= 5; i++) { printf("%d ", i); }

2. while Loop

Used when the condition is checked before execution.

Syntax

while (condition) { statements; }

Example

int i = 1; while (i <= 5) { printf("%d ", i); i++; }

3. do–while Loop

Used when the loop must execute at least once.

Syntax

do { statements; } while (condition);

Example

int i = 1; do { printf("%d ", i); i++; } while (i <= 5);

Differences Between Loops

Featureforwhiledo–while
Condition checkBefore loopBefore loopAfter loop
Minimum execution0 times0 timesAt least 1 time
Use caseKnown countUnknown countExecute once minimum

Loop Control Statements

break

Terminates the loop.

break;

continue

Skips the current iteration.

continue;

Nested Loops

A loop inside another loop.

for (int i = 1; i <= 3; i++) { for (int j = 1; j <= 3; j++) { printf("* "); } printf("\n"); }

Summary

  • Loops repeat execution of statements

  • for loop is used for fixed iterations

  • while loop checks condition first

  • do–while loop executes at least once

  • break and continue control loop flow


πŸ”’ Some advanced sections are available for Registered Members
Register Now

Share this Post


← Back to Tutorials

Popular Competitive Exam Quizzes

πŸ€– AI Quizer Assistant

πŸ“ Quiz
πŸ“š Categories
πŸ† Leaderboard
πŸ“Š My Score
❓ Help
πŸ‘‹ Hi! I'm your AI quiz assistant for Quizer.in!

I can help you with:
β€’ πŸ“ Finding quizzes
β€’ πŸ† Checking leaderboard
β€’ πŸ“Š Your performance stats

Type 'help' to get started! πŸš€
AI is thinking...