C Programs to demonstrate use of continue statement in All three types of Loops (for, while and do while loop), Difference Between break and continue
The continue statement skips the remaining statements of the current iteration and continues with the next iteration of the loop.
C में continue statement current iteration के बाकी statements को skip करके loop की अगली iteration शुरू करता है।
Syntax
continue;1. continue Statement in for Loop
C Program
#include <stdio.h>int main(){int i;printf("Counting from 1 to 10\n");for (i = 1; i <= 10; i++){if (i == 7)continue;printf("%d\n", i);}return 0;}
Output
Counting from 1 to 101234568910
Effect: When i becomes 7, continue skips the printf() statement. Therefore, 7 is not printed, but the loop continues.
जब i की value 7 होती है, तो continue printf() statement को skip कर देता है। इसलिए 7 print नहीं होता, लेकिन loop चलता रहता है।
2. continue Statement in while Loop
C Program
#include <stdio.h>int main(){int i = 0;printf("Counting from 1 to 10\n");while (i < 10){i++;if (i == 7)continue;printf("%d\n", i);}return 0;}
Output
Counting from 1 to 101234568910
Effect: When i becomes 7, continue skips the printf() statement and moves control to the next iteration. The number 7 is not printed.
जब i की value 7 होती है, तो continue printf() को skip करके अगली iteration शुरू करता है। इसलिए 7 print नहीं होता।
3. continue Statement in do-while Loop
C Program
#include <stdio.h>int main(){int i = 0;printf("Counting from 1 to 10\n");do{i++;if (i == 7)continue;printf("%d\n", i);}while (i < 10);return 0;}
Output
Counting from 1 to 101234568910
Effect: When i becomes 7, continue skips the printf() statement and transfers control to the do-while loop condition.
जब i की value 7 होती है, तो continue printf() statement को skip करके do-while loop की condition पर control भेजता है।
Difference Between break and continue
breakterminates the entire loop.continueskips only the current iteration and continues with the next iteration.breakपूरे loop को terminate कर देता है।continueकेवल current iteration को skip करके अगली iteration शुरू करता है।
The continue statement is useful when we want to skip a particular iteration without terminating the entire loop.
continue statement तब उपयोगी होता है जब हमें किसी particular iteration को skip करना हो, लेकिन पूरे loop को terminate नहीं करना हो।
Comments
Post a Comment