Scripting >> Python >> Examples >> Loops >> Using break and continue in for or while loopsbreak The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. If break statement is inside a nested loop (loop inside another loop), break will terminate the innermost loop
Example 1: using break in a for loop
Example 2: using break in a while loop
continue The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration
Example 3: using continue in for loop
Example 4: using continue in while loop
|