Suppose you have used a loop that must run 10 times. In 5th iteration a condition occurs when you have to terminate the loop. All you need to do is add the break statement with this condition. It is specified with if conditional construct. After 5th iteration the loop will break and the next statement after loop will execute. The rest of 5 iterations will not execute.
Example- display first 5 even numbers in given list using while loop with break statement.
In the above coding example the loop is terminated with a break statement as soon as the count variable becomes 5. It is incremented each time an even number is encountered in the array numArray.
Example- display even numbers after 5th element in the given list using continue in a for loop
In this example the first five iterations will be executed without checking the number for being even. This is done with continue in the loop with condition (ctr<5). After fifth iteration remaining array elements are checked and printed if they are even.