DMCA.com Protection Status C Programming – Day 4 | Loops in C (for, while, do-while) Explained for Beginners - ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer ZAREEN TECH WAVE -Largest Tutorials Website For Freelancer

Header Ads

C Programming – Day 4 | Loops in C (for, while, do-while) Explained for Beginners

LOOP IN C (for, while, do-while)

DAY - 4




let’s begin 🚀


📍 Day-4 — Loops in C (for, while, do-while)

Loops repeat a block of code many times ✅


✅ 1️⃣ for Loop

Used when number of repetitions is known

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

Output:

1 2 3 4 5

✅ 2️⃣ while Loop

Used when number of repetitions is unknown

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

✅ 3️⃣ do-while Loop

Executes block at least once

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

✅ Difference Summary

Featureforwhiledo-while
Initialization in loopYesNoNo
Condition check first✅ Yes✅ Yes❌ Executes once first
Guaranteed at least once?❌ No❌ No✅ Yes

🧮 Example: Multiplication Table

int n; scanf("%d", &n); for(int i=1; i<=10; i++){ printf("%d x %d = %d\n", n, i, n*i); }

✅ Task-4

Write a program to:

✔ Input a number
✔ Using while loop
✔ Print sum of digits

Example:

Input: 456 Output: 15

(Because 4+5+6 = 15)

📌 Hint:

  • %10 → last digit

  • /10 → remove last digit

✅ Send me your code — I will fix if needed


📝 Quick Quiz — Day-4

Reply like: 1C, 2A, 3B

1️⃣ Which loop runs at least once always?
A) for
B) while
C) do-while

2️⃣ Repeat 1 to 10 → which loop is best?
A) for
B) while
C) switch

3️⃣ %10 gives:
A) Division
B) Last digit
C) Whole number


✅ Your turn now!

Send:
👉 Task-4 code
👉 Day-4 quiz answers


No comments

Thank You For Visit My Website.
I Will Contact As Soon As Possible.

Theme images by 5ugarless. Powered by Blogger.