#include <iostream.h>
int main()
{
// x declared here so it can be used after the loop
int x;
for ( x = 1; x <= 10; x++ ) {
if ( x == 5 )
break; // break loop only if x is 5
cout << x << " ";
}
cout << "\nBroke out of loop at x of " << x << endl;
return 0;
}
OUTPUT:
1 2 3 4
Broke out of loop at x of 5
No comments:
Post a Comment