Difference between break and continue in Python
Difference between continue and break
- break forces the execution to exit or “break” the loop in which it is present
- break forces the execution to jump out of the closest enclosing loop
- The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. If it is inside a nested loop (loop inside another loop), break will terminate the innermost loop
- continue forces the control to skip the rest of the code for the current iteration and continues with the next iteration/code
- continue forces the execution to jump to the top of the closest enclosing loop
- The continue statement is used to skip the rest of the code inside a loop for the current iteration only. The continue statement does not terminate the loop if there is a next iteration as per the loop condition