I l @ ve RuBoard |
The keywords for program jumps are break , continue , and goto .
The three instructions break , continue , and goto cause program flow to jump from one location of a program to another location.
The break command can be used with any of the three loop forms and with the switch statement. It causes program control to skip the rest of the loop or switch containing it and to resume with the next command following the loop or switch .
switch (number) { case 4: printf("That's a good choice.\n"); break; case 5: printf("That's a fair choice.\n"); break; default: printf("That's a poor choice.\n"); }
The continue command can be used with any of the three loop forms, but not with a switch . It causes program control to skip the remaining statements in a loop. For a while or for loop, the next loop cycle is started. For a do while loop, the exit condition is tested and then, if necessary, the next loop cycle is started.
while ((ch = getchar()) != EOF) { if (ch == ` ') continue; putchar(ch); chcount++; }
This fragment echoes and counts nonspace characters .
A goto statement causes program control to jump to a statement bearing the indicated label. A colon is used to separate a labeled statement from its label. Label names follow the rules for variable names . The labeled statement can come either before or after the goto .
goto label ; label : statement
top : ch = getchar(); if (ch != `y') goto top;
I l @ ve RuBoard |