Jump Statement in Python with Examples

Jump statement is used to transfer the control from one part of program to another part. In Python, There are three types of Jump statements.

  • break
  • continue
  • pass

break

The break statement immediately terminates a loop and control of the program go the next body of the loop. When the break statement is executed, the control flow of the program comes out of the loop and starts executing the segment of code after the loop structure.

Syntax of break:

break

The above program will repeat the iteration with the given “Iterathon” as a string. Each letter of the given string sequence is tested till the letter ‘e’ is encountered, when it is encountered the control is transferred outside the loop block or it terminates.

As shown in the output, it is displayed till the letter ‘e’ is checked after which the loop gets terminated and finally get “Iter” as a output.

continue

Continue statement is used to skip the remaining part of a loop and start with next iteration. It is unlike a break statement.

Syntax of continue statement:

continue

python virtual image

In the above example, After a condition was fulfilled, continue statement continue a current iteration and give output as “Iterathon”. The difference between a break and continue, A break statement terminates the loop after condition is fulfilled, but continue statement continue the loop even the condition is fulfilled.

pass

pass statement in Python programming is a null statement. pass statement when executed by the interpreter it is completely ignored. Nothing happens when pass is executed. pass is generally called as placeholder.

Syntax of pass statement:

pass

python virtual example

we cannot develop such functions or loops with empty body segment because the interpreter would raise an error. So, to avoid this we can use pass statement to construct a body that does nothing.

My Previous Post

Loops construction in Python: https://iterathon.tech//loops-construction-in-python-for-beginners/

LEARN LITTLE BY LITTLE TO CHANGE THE TECH WORLD

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *