For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

Python Jump Statements

Jump Statements

Jump Statements are used to pass the program's control from one location to another. Means these are used to modify the flow of a loop like-to skip a part of a loop or terminate a loop.

  1. Break

    It is used to terminate the loop.

    for val in "string":  
          if val == "i":  
                 break  
          print(val) 

    In the above code, we break the loop as soon as "i" is encountered, hence printing "str".

  2. continue

    It is used to skip all the remaining statements in the loop and transfer controls back to the top of the loop.

    for val in "init":  
          if val == "i":  
                continue  
           print(val)  
    print(" The End") 

    In the above code, we are printing "nt", because it will skip letter "i".

  3. pass

    It can be used when a statement is required syntactically but you do not want any code to execute.

    for i in "init":  
          if(i == "i"):  
                pass  
          else:  
               print(i) 

    Continue forces the loop to start the next iteration while pass means "there is no code for execution" and will continue through the remainder of the loop body.The output will be "nt".