-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dba4c2
commit adcbcb7
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Break | ||
|
||
`Break` can come in switch or a body of loop. `Break` is used to exit the loop or switch statement. | ||
|
||
```c | ||
for (n=1;, n<=500; n+1) | ||
{ | ||
for (i = 2; i <= n/2; i++) | ||
|
||
{ | ||
if (n%i == 0) | ||
break; | ||
} | ||
|
||
if (i == n/2 + 1) | ||
printf("%d\n", n); | ||
} | ||
``` | ||
|
||
|
||
# Continue | ||
|
||
`Continue` can come only in body of a loop. `Continue` is used to skip the current iteration and continue with the next iteration of the loop by bringing the control at the begining of body of loop. | ||
|
||
```c | ||
for (i = 1; i <= 10; i++) | ||
{ | ||
if (i == 5) | ||
continue; | ||
if (i == 6) | ||
break; | ||
printf("%d\n", i); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
jumping to a specific location in the program. | ||
|
||
```C | ||
int main() { | ||
int x = 5; | ||
if (x < 0) { | ||
goto error; | ||
} | ||
// Code to be executed when x is positive | ||
return 0; | ||
error: | ||
printf("Error: x is negative\n"); | ||
return -1; | ||
} | ||
``` | ||
|
||
```C | ||
int complex_function(void) { | ||
if (initialize_1() != SUCCESS) { goto out1; } | ||
if (initialize_2() != SUCCESS) { goto out2; } | ||
if (initialize_3() != SUCCESS) { goto out3; } | ||
|
||
/* other statements */ | ||
|
||
return SUCCESS; | ||
|
||
out3: | ||
deinitialize_3(); | ||
out2: | ||
deinitialize_2(); | ||
out1: | ||
deinitialize_1(); | ||
return ERROR; | ||
} | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters