Let’s learn how to use control statements like break, continue, and else clauses in the for loop and the while loop. The for loop and while loop have control statements break and continue to handle these situations.

The break statement is used to terminate the execution of the for loop or whileloop, and the control goes to the statement after the body of the for loop. Example: In the for loop, when the condition i==3 is satisfied, it will break the for loop, and the control will go to the statement after the body of the for loop, i.e., print (“Outside the for loop”).

The else clause is not executed when the for loop is terminated by a break statement.

Related Articles