filmov
tv
What are Loop Control Statements in Python | EP-42 Break, Continue & Pass in Python | Python Loops
Показать описание
Loop control statements change execution from their normal sequence.
When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements:
1. Break statement
2. Continue statement
3. Pass statement
"""
1. Python Break Statement
"""Python break is used to terminate the execution of the loop.
break statement in Python is used to bring the control out of the loop when some external condition is triggered. break statement is put inside the loop body (generally after if condition). It terminates the current loop, i.e., the loop in which it appears, and resumes execution at the next statement immediately after the end of that loop. If the break statement is inside a nested loop, the break will terminate the innermost loop.
syntax:
Loop{
Condition:
break
}
"""
for i in range(11):
print(i)
if i == 4:
break
for i in range(1,16):
mul = i * 3
print(mul,"mul")
if mul == 30:
break
2. Python Continue Statement
syntax:
loop
if condition:
continue
else:
print(x)
"""
for i in range(1,11):
if i==1:
continue
else:
print(i,"continue")
3. Python Pass Statement
"""
The Python pass statement is a null statement. But the difference between pass and comment is that comment is ignored by the interpreter whereas pass is not ignored.
Syntax:
pass
When the user does not know what code to write, So user simply places a pass at that line. Sometimes, the pass is used when the user doesn’t want any code to execute. So users can simply place a pass where empty code is not allowed, like in loops, function definitions, class definitions, or in if statements. So using a pass statement user avoids this error."""
for i in range(10):
pass
#PythonTutorial #PythonProgramming #PythonLoops #LoopControlStatements #PythonForBeginners #PythonBreakContinuePass #LearnPython #CodingTutorial #ProgrammingTips #PythonBasics #Python #LoopControl #BreakContinuePass #ProgrammingTutorial #LearnPython #Code #Developer #Break #Continue #Pass
Connect With Us:
—————————————
When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements:
1. Break statement
2. Continue statement
3. Pass statement
"""
1. Python Break Statement
"""Python break is used to terminate the execution of the loop.
break statement in Python is used to bring the control out of the loop when some external condition is triggered. break statement is put inside the loop body (generally after if condition). It terminates the current loop, i.e., the loop in which it appears, and resumes execution at the next statement immediately after the end of that loop. If the break statement is inside a nested loop, the break will terminate the innermost loop.
syntax:
Loop{
Condition:
break
}
"""
for i in range(11):
print(i)
if i == 4:
break
for i in range(1,16):
mul = i * 3
print(mul,"mul")
if mul == 30:
break
2. Python Continue Statement
syntax:
loop
if condition:
continue
else:
print(x)
"""
for i in range(1,11):
if i==1:
continue
else:
print(i,"continue")
3. Python Pass Statement
"""
The Python pass statement is a null statement. But the difference between pass and comment is that comment is ignored by the interpreter whereas pass is not ignored.
Syntax:
pass
When the user does not know what code to write, So user simply places a pass at that line. Sometimes, the pass is used when the user doesn’t want any code to execute. So users can simply place a pass where empty code is not allowed, like in loops, function definitions, class definitions, or in if statements. So using a pass statement user avoids this error."""
for i in range(10):
pass
#PythonTutorial #PythonProgramming #PythonLoops #LoopControlStatements #PythonForBeginners #PythonBreakContinuePass #LearnPython #CodingTutorial #ProgrammingTips #PythonBasics #Python #LoopControl #BreakContinuePass #ProgrammingTutorial #LearnPython #Code #Developer #Break #Continue #Pass
Connect With Us:
—————————————