break
statement in Python is used to terminate the loop prematurely. When the break
keyword is encountered, the loop is immediately stopped, and control is passed to the first statement outside the loop.break
statement:
Example Output:
Explanation:break
statement exits the loop immediately, avoiding the unnecessary checks for the remaining characters.continue
statement in Python is used to skip the rest of the code inside the loop for the current iteration. When continue
is encountered, control jumps to the next iteration of the loop, bypassing any code below it.continue
is encountered, the loop doesn’t exit but moves directly to the next iteration, allowing the program to skip processing the current iteration’s remaining code.continue
statement, skipping over non-matching characters:
Example Output:
Explanation:continue
statement ensures that only the character “A” will trigger the print statement.pass
statement in Python is a placeholder that does nothing. It’s often used when a statement is syntactically required but you don’t want to implement any functionality yet.pass
comes in handy:
Example Output:
Explanation:pass
statement does nothing when the character is “A”, and the loop continues to print the other characters.break
, continue
, and pass
.break
statement is used to exit a loop early, transferring control to the next statement outside the loop.break
and continue
statements?break
exits the loop, whereas continue
skips the current iteration and moves to the next one.continue
statement inside an if
statement in Python?continue
statement can be used inside if
statements to skip over specific conditions within the loop.pass
keyword in Python?pass
keyword is used as a placeholder in empty code blocks, allowing the program to run without any errors.