0% found this document useful (0 votes)
5 views11 pages

GCC Week 2 Lec 2

Uploaded by

Aleena Zahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

GCC Week 2 Lec 2

Uploaded by

Aleena Zahid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

GIRLS CODING CAMP

WEEK 2
NESTED IF
STATEMENTS
LOOPS
LOOPS IN
PYTHON
Understanding
for and while
loops with
examples
What is a Loop? 🤔
A loop allows repeated execution of
code.

It is a way to repeat a set of


instructions multiple times until a
certain condition is met.

It helps automate repetitive tasks,


without writing the same code again
and again.
TWO MAIN TYPES IN
PYTHON
for loop – Iterates over
sequences

while loop – Runs until a


condition is met
THE FOR LOOP

Syntax: Example:
for i in range(3):
for variable in range(n): print("Hello, World!")
# Code to execute
output:
Hello, World!
Hello, World!
Hello, World!
USING RANGE(START, STOP, STEP)

for i in range(2, 10, 2):


range(start, print(i)
stop, step) can
output:
control the 2
range. 4
6
8
THE WHILE LOOP

A while loop syntax:


runs until a
condition while condition:
becomes # Code to execute
False.
Example

x=3 output:
while x > 0: 3
print(x) 2
x -= 1 1
Infinite Loops
If a loop condition never becomes False, it runs forever.

while True:
print("This will never stop!")

Always ensure exit conditions !


The break Statement
for i in range(10): Output:
if i == 5: 0
break 1
print(i) 2
3
4

You might also like