Using goto. - C++ Statement

C++ examples for Statement:goto

Description

Using goto.

Demo Code

#include <iostream> 
#include <iomanip> 
using namespace std; 

 int main() /*www. j  a  v a 2s.  com*/
 { 
     int count = 1; 

     start: // label 
        // goto end when count exceeds 10 
         if ( count > 10 ) 
            goto end; 

         cout << setw( 2 ) << left << count; 
         ++count; 

         // goto start on line 17 
         goto start; 

     end: // label 
         cout << endl; 
 }

Result


Related Tutorials