Escolar Documentos
Profissional Documentos
Cultura Documentos
(Week6)
https://www.tutorialspoint.com/python3/python_basic_operators.htm
Overview
While loop
For loop
Break statement
Continue statement
Loops
A loop statement allows to execute a statement or
group of statements multiple times
While loop
Repeats a statement or group of statements while
a given condition is TRUE.
It tests the condition before executing the loop
body.
Syntax
Syntax
range() function
built-in function range() is used to iterate over a
sequence
break statement
continue statement
pass statement
break statement
Terminates the loop statement and transfers
execution to the statement immediately following
the loop
most common use of break is when some
external condition is triggered requiring a hasty
exit
break (example)
break (example)
continue statement
Causes the loop to skip the remainder of its body
and immediately retest its condition prior to
reiterating
continue statement in Python returns the control
to the beginning of the current loop
continue (example)
Sample 1
Write a Python program that calculates the sum
of the numbers from 1 to 100
Sample 1
Write a Python program that calculates the sum
of the numbers from 1 to 100
Sample 2
Use an if else statement in combination with a
while loop to calculate the sum of natural
numbers upto num
Sample 2
used an if else statement in combination with a
while loop to calculate the sum of natural
numbers upto num
Sample 3
Write a program to find a factorial of a number
Sample 3
Write a program to find a factorial of a number