So break and continue theoretically same as other programming language.taking a small example to demonstrate both in Python.
break example:
student_names = ["james" ,"Mark", "Abhinaw", "Arudhra" ,"Rajat", "Gaurav"]
for name in student_names:
if name == "Arudhra":
print("Found him!" + name)
break
print("Currently testing " + name)
Output:
Currently testing james
Currently testing Marks
Currently testing Abhinaw
Found her! Arudhra
continue example:
student_names = ["james" ,"Mark", "Abhinaw", "Arudhra" ,"Rajat", "Gaurav"]
for name in student_names:
if name == "Arudhra":
print("Found him!" + name)
continue
print("Currently testing " + name)
Output:
Currently testing james
Currently testing Marks
Currently testing Abhinaw
Currently testing Rajat
Currently testing Gaurav
we see that except for Arudhra .it print all names.
No comments:
Post a Comment