Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

break pass continue python

# ---------------------------
# -- Continue, Break, Pass --
# ---------------------------

myNumbers = [1, 2, 3, 5, 7, 10, 13, 14, 15, 19]

# Continue ==> Skip The ( Specific Element ) And Continue 

for numbers in myNumbers :

  if numbers == 13 :

      continue

  print( numbers )

print( "_" * 100 ) # -- Separator --

# Pass ==> Skip Any Program If I Completed Or Not

for numbers in myNumbers :
  pass

print( "Here We Have 'pass'." )

print( "_" * 100 ) # -- Separator --

# Break ==> Stop The Function

for numbers in myNumbers:

  if numbers == 13:

    break

  print( numbers )
  
Comment

Example of break, continue and pass statements in python

def main():
    check = input("Are you a new student(yes/no): ")
    if check == "yes":
        pass
    elif check == "no":
        totalMarks = 0
        numOfSub = 0
        while True:
            marks = input( 'Marks for subject ' + str(numOfSub +1) + ": ")
            if marks == '':
                break
            marks = float(marks)
            if marks < 0 or marks >100:
                print("Invalid marks")
                continue
            numOfSub = numOfSub+1
            totalMarks = totalMarks + marks
        percentage = totalMarks/numOfSub
        print("Total marks: ", totalMarks)
        print("Number of Subject is: ", numOfSub)
        print("Percentage: ", round(percentage,2))
    else:
        print("enter a valid response")
main()
Comment

break continue pass in python

# break - used to terminate the loop or statement
# continue - skip the current iteration and continue from the next
# pass - continue the statement, often used as a placeholder to execute
# 		 empty loops/statements
Comment

PREVIOUS NEXT
Code Example
Python :: pandas replace values from another dataframe 
Python :: python increment by 1 
Python :: python add list 
Python :: is login a class in python 
Python :: concatenate string in python 
Python :: remove timezone from a datetime object? 
Python :: full form of api 
Python :: time converting module 
Python :: numpy add 
Python :: heroku how to access config vars django 
Python :: how to sort numpy array 
Python :: python iterating through a list 
Python :: python code variable declaration 
Python :: python map 
Python :: python turtle tutorial 
Python :: how to earn money as a python developer 
Python :: leetcode python 
Python :: How to solve not in base 10 in python when using decimals 
Python :: celery periodic tasks 
Python :: django-multivaluedictkeyerror-error 
Python :: dictionary with list as values 
Python :: função map python 
Python :: dfs 
Python :: comment all selected lines in python 
Python :: custom permission class django rest framework 
Python :: dot product of two vectors python 
Python :: how to remove item from list in python 
Python :: try and exception 
Python :: map python 
Python :: Unreadable Notebook: jpyter 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =