Featured
- Get link
- X
- Other Apps
Loop control statement
In order to manage loop we have loop control statement. They allow us to manipulate the flow of loop at a specific point
There are three types of loop statement:
2. Continue statement
3. Pass
Break statement:
In break statement we can end a loop immediately that is the next iteration of loop will not be executed and move out of the loop
while num<10
num=num+1
if num==5:
break
print(num)
Print("loop ended")
Continue statement:
If we don't want to break the entire loop, only to skip one iteration then we can use the continue statement
while
num=num+1
if num==5:
continue
print(num)
print("completed ")
In this example we always increase number one by one and then print it but if the number is five we skip the iteration so this number doesn't get printed
(In simple it will not end the loop it will skip the particular iteration)
Pass statement:
It is special statement sincs it does absolutely nothing. It is not a loop control statement but a place holder for code
pass
else:
pass
pass
Sometimes you want to write your basic code structure, without implementing the logic yet. In this case, we can use the pass statement, in order to fill the code blocks. Otherwise, we can’t run the script.
- Get link
- X
- Other Apps


Comments
Post a Comment