A goto statement is used to branch (transfer control) to another location in a program.
#include <stdio.h>
#include <stdlib.h>
int main () {
unsigned Count;
unsigned x;
Count = rand () % 7;
printf ("The count is %i. \nThis is ", Count);
switch (Count) {
case 0:
printf ("none.\n");
goto next;
case 1:
printf ("only one.\n");
goto next;
case 2:
printf ("a pair.\n");
goto next;
case 3:
printf ("three.\n");
goto next;
default:
printf ("many.\n");
goto next;
}
next:
x = rand () % 5;
printf ("The test number is %i.\n", x);
while (x < 10) {
++x;
if (x % 2 == 0) {
goto done;
}
printf ("%i is an odd number.\n", x);
}
done:
return 0;
}
| Break Statement | <break-statement> |
| Continue Statement | <continue-statement> |
| MSDN | The C goto Statement |
|
C Now
| C GoTo Statement |
| C++ Now | C++ GoTo Statement |
| C# Now | C# GoTo Statement |
| COBOL Now | COBOL GoTo Statement |
| FORTRAN Now | FORTRAN GoTo Statement |
| Java Now | Java GoTo Statement |
| JavaScript Now | JavaScript GoTo Statement |
| Pascal Now | Pascal GoTo Statement |
| Perl Now | Perl GoTo Statement |
| PHP Now | PHP GoTo Statement |