In this section, you will learn how to use break statement in a for loop.
The break statement terminates the execution of the enclosing loop or conditional statement. In a for loop statement, the break statement can stop the counting when a given condition becomes true. You can see in the given example that the program is supposed to count the numbers from 1 to 20 using for loop. As per the condition defined the break statement stop the execution of the loop as soon as it detects the number 5 .
Here is the code:
Output will be displayed as:
As the number 5 comes, the execution of the loop gets terminated.
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: February 5, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles