Loops in C – Hindi में पूरी जानकारी (Examples, Types, Flowcharts और FAQs)

1

Programming में कई बार हमें किसी काम को बार-बार दोहराना पड़ता है—जैसे 1 से 100 तक नंबर प्रिंट करना, किसी table का generation करना, किसी array के हर element को read करना आदि। अगर हम ये सब manually लिखें तो कोड बहुत बड़ा और error-prone बन जाएगा।
इसी समस्या को solve करने के लिए C Language में Loops का उपयोग किया जाता है।

इस लेख में हम C के सभी loops को आसान भाषा में समझेंगे—with examples, flowcharts, best practices, और साथ-साथ जरूरी internal links भी जोड़ेंगे ताकि आपकी website की SEO power बढ़े


🟦 Loop in C क्या है?

Loop एक ऐसा control structure है जो किसी statement या block of code को तब तक बार-बार execute करता है, जब तक कोई condition true रहती है।

C में तीन मुख्य प्रकार के loops होते हैं:

  1. for loop
  2. while loop
  3. do…while loop

इसके अलावा दो special loop control statements:

  • break
  • continue

🟩 Loop की जरूरत क्यों पड़ती है?

Programming में loops का इस्तेमाल इन कामों के लिए किया जाता है:

  • किसी list/array को traverse करने के लिए
  • किसी value को बार-बार print करने के लिए
  • Mathematical series generate करने के लिए
  • Repetitive tasks को automate करने के लिए
  • Memory और time save करने के लिए

🟧 Loop Structure (Basic Idea)

हर loop तीन parts में काम करता है:

  1. Initialization (शुरुआती setup)
  2. Condition Check
  3. Update/Increment/Decrement

अगर condition true है → loop चलता रहेगा
अगर false हो जाए → loop बंद (exit)


🔵 PART 1 — For Loop in C

C में सबसे ज्यादा उपयोग होने वाला loop।

Syntax

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

Example: 1 से 10 तक नंबर print करना

#include <stdio.h>

int main() {
    for(int i = 1; i <= 10; i++) {
        printf("%d\n", i);
    }
    return 0;
}

कैसे काम करता है:

  • i = 1 (initial)
  • condition check → i ≤ 10 → true
  • print i
  • i++
  • फिर से loop शुरू
  • जब i = 11 → loop बंद

🔵 PART 2 — While Loop in C

जब हमें पता न हो कि loop कितनी बार चलेगा (unknown iterations), तब while उपयोग करते हैं।

Syntax

while(condition) {
    // code
}

Example: 1 से 5 तक print करना

int i = 1;

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

🔵 PART 3 — Do…While Loop in C

Ye loop पहले code execute करता है और बाद में condition check करता है।

👉 मतलब ये कम से कम एक बार जरूर चलेगा

Syntax

do {
    // code
} while(condition);

Example:

int i = 1;

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

🔵 PART 4 — Nested Loops

Loop के अंदर loop को nested loop कहते हैं।

Example: Stars pattern print करना

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

Output:

*
* *
* * *
* * * *
* * * * *

🔵 PART 5 — Loop Control Statements

1. break

Loop को बीच में ही बंद कर देता है।

Example:

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

Output:

1 2 3 4

2. continue

Current iteration skip करता है और next पर चला जाता है।

Example:

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

Output:

1 2 4 5

🌟 Real-Life Example — Sum of 1 to N

int n, sum = 0;
printf("Enter N: ");
scanf("%d", &n);

for(int i = 1; i <= n; i++) {
    sum += i;
}

printf("Sum = %d", sum);

🔗 Related Topic: C Variables

C programming में variables सबसे basic building blocks हैं।
Variables का use data को store करने के लिए किया जाता है।

➡️ यहाँ पढ़ें: C Variables


🔗 Related Topic: C Operators

Loops में conditions check करने के लिए हम operators का use करते हैं—जैसे <, <=, ==, != आदि।

➡️ यहाँ पढ़ें: C Operators in Hindi


🔗 Related Topic: Loop in C

Large programs को छोटे blocks में divide करने के लिए functions का use किया जाता है।
Loops अक्सर functions के अंदर use होते हैं।

➡️ यहाँ पढ़ें: Loop in C


❓ FAQs About Loops in C

Q1. C में सबसे ज्यादा कौन सा loop उपयोग होता है?

for loop, क्योंकि यह simplest और predictable होता है।

Q2. while और do-while में अंतर?

  • while → पहले condition check
  • do-while → पहले code execute, बाद में condition check

Q3. क्या loop infinite हो सकता है?

हाँ। Condition हमेशा true रहे तो infinite loop बन जाएगा।

Example:

while(1) {
    // endless loop
}

Conclusion

Loops C programming का एक powerful concept है जो repetitive tasks को आसान और fast बनाता है।

One thought on “Loops in C – Hindi में पूरी जानकारी (Examples, Types, Flowcharts और FAQs)

Comments are closed.