// break statement exiting a for statement.
#include <iostream>
using namespace std;
int main()
{
unsigned int count; // control variable also used after loop terminates
for ( count = 1; count <= 10; ++count ) // loop 10 times
{
if ( 5 == count ) // if count is 5,
break; // break loop only if x is 5
cout << count << " ";
} // end for
cout << "\nBroke out of loop at count = " << count << endl;
} // end main






0 comments:
Post a Comment