
 |
![]() |
|
|
|
|
 |
The break Statement
This next example is a more advanced for loop, using the break keyword. The break keyword is used to break off in a loop. The break statement jumps over all the rest of the statements in the loop's block and goes to the next statement after the loop. Here is the example:
In this example, we still used a for loop, but we excluded all three control parts of the loop, this would have caused an infinite loop but we added the break keyword to stop it. The line that calculates the average is, << (float) sum / count << endl; this line takes the sum and divides it by count and converts it to float, so you get a decimal answer.Please Rate this Code:
|
|
|
|
|
|
|