Login    New User    Forgot Password    Help      

Goto Statements

GO TO INDEX

Goto Statements

The goto statement is a control flow statement that causes the CPU to jump to another spot in the code. This spot is identified through use of a statement label. The following is an example of a goto statement and statement label:

Goto

                               

#include < iostream·h>
#include< iomanip·h> int main() { int count = 1; start: if ( count > 5 ) goto end; cout << count << "\n\n"; ++count; goto start; end: cout << endl; return 0; }

OUTPUT

1

2

3

4

5
                                     

In this example without using loop it prints the number from 1 to 5,using goto statement compiler goes to the start tag when goto statement encounters

GO TO INDEX