C break and continue
Explanation (English): The break
and continue
statements are used to control the flow of loops in C. break
is used to exit a loop prematurely, and continue
is used to skip the current iteration and move to the next one.
व्याख्या (हिंदी): C प्रोग्रामिंग में break
और continue
का इस्तेमाल loop को नियंत्रित करने के लिए किया जाता है। break
loop को बीच में ही रोक देता है और continue
वर्तमान चक्कर को छोड़कर अगले चक्कर पर चला जाता है।
Break Statement Example
#include <stdio.h>
int main() {
for(int i = 1; i <= 10; i++) {
if(i == 5)
break;
printf("%d\n", i);
}
return 0;
}
Explanation: The loop stops when i == 5
. It prints 1 to 4 only.
व्याख्या: जब i == 5
होता है, break
स्टेटमेंट लूप को रोक देता है। यह केवल 1 से 4 तक ही प्रिंट करता है।
Continue Statement Example
#include <stdio.h>
int main() {
for(int i = 1; i <= 5; i++) {
if(i == 3)
continue;
printf("%d\n", i);
}
return 0;
}
Explanation: When i == 3
, it skips printing 3 and continues with 4 and 5.
व्याख्या: जब i == 3
होता है, continue
स्टेटमेंट उस iteration को छोड़ देता है। यह 1, 2, 4, 5 प्रिंट करेगा लेकिन 3 को छोड़ देगा।