Python Basics II – Loops and Control Flow.pptx

AAplayz77 9 views 8 slides Aug 30, 2025
Slide 1
Slide 1 of 8
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8

About This Presentation

...


Slide Content

Python Basics II – Loops and Control Flow

Todays session What are loops in Python? while loop – repeating based on condition for loop – repeating over sequences range() function Using break and continue Nested loops

What are loops? Loops allow you to repeat a set of instructions automatically. Instead of writing the same code multiple times, you use a loop to run it many times with less code.

while loop A while loop keeps on repeating when its condition is true Python checks the condition before each repetition

Example x = 15 If x >= 9: print(x) x = x-1

for loop A for loop is used to loop through a sequence (like a list, string, or a range of numbers) `

Example for i in range(1, 6): print("Number:", i )

range() The range() function creates a sequence of numbers Example: range(5) → 0, 1, 2, 3, 4 range(1, 6) → 1, 2, 3, 4, 5 range(1, 10, 2) → 1, 3, 5, 7, 9
Tags