Posts

Showing posts with the label break and continue

Python3 break and continue Statements

Image
Python break and continue Statements break and continue statements              In Python , break and continue statements can alter the flow of normal loop. Loop iterate over a block of code until test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression.   The break and continue statements are used in these cases. Python Break Statement     Syntax:                 break Flow Chart:                                         Working:                     Eg:        nums=[1,2,3,4]        for num in nums:              if num==4:                   break              print(num)        else:              print("in the else block")        print("outside of for loop")   Output:: 1                        2                        3                        outside of for loop     Python program to check given number is prime number or not (using break):        num=int(input("enter a number: &quo