C++ goto statement end the loop rather than a break

Description

C++ goto statement end the loop rather than a break

#include <iostream> 
  
using namespace std; 
  
int main(int argc, const char * argv[]) 
{ 
        unsigned int array[10]; 
        unsigned int count = 0; 
      //  w  ww . ja v  a2s .c o m
        do 
        { 
            if ((count % 2) == 0) 
            { 
                ++count; 
                continue; 
            } 
          
            array[count] = count; 
            cout << "Loop Iteration: " << array[count++] << endl; 
              
            if (count == 10) 
            { 
                goto finished; 
            } 
        } while (true); 
    finished: 
        return 0; 
}



PreviousNext

Related