Dragona_Pro

๐Ÿ”ฐ Introduction :

The current image has no alternative text. The file name is: IMG_20250722_015811_edit_55078523238469-1-scaled.jpg

In programming, we often need to repeat the same code multiple times. For example:

Printing numbers from 1 to 10.

Checking elements in a list.

Repealing a game until the player loses.

Instead of manually repeating the code, we use for and while loops.

๐ŸŒ€ First: The for loop

โœ… General form :

Python

for a variable in an array:

# Iterate code

๐Ÿ“ฆ The most famous example โ€“ using range():

Python

for i in range(5):

print(i)

๐Ÿ“Œ Result :

0

1

2

3

4

๐Ÿ”Ž range(5) means: from 0 to 4 (5 not included).

๐Ÿ” Printing numbers from 1 to 10 :

Python

for i in range(1, 11):

print(i)

๐Ÿช„ Simple exercise :

Write code that prints the sentence “Hello!” Five times:

Python

for i in range(5):

print(“Hello!”)

๐Ÿงฎ Practical example: Multiplication table

Python

number = int(input(“Pick a number: “))

for i in range(1, 11):

print(number, “x”, i, “=”, number * i)

๐Ÿ”„ Second: The while loop

โœ… General form :

Python

while condition:

# code that repeats

๐Ÿ“Œ The while is used when you don’t know the number of iterations in advance.

โณ Simple example :

Python

i = 1

while i <= 5:

print(“Repeat number”, i)

i += 1

โš ๏ธ Important warning :

Beware of infinite loops! If you forget to update the condition inside the while statement, it will run forever:

python

# This code will not stop!

while True:

print(“Always on”)

๐Ÿงช Exercise 1 :

Ask the user for a password, and repeat the request until they type it correctly:

python

password = “”

while password != “python123”:

password = input(“Enter password: “)

print(“Login successful!”)

๐Ÿ” Exercise 2 :

Write code that asks the user for a number, then prints from 1 up to that number:

python

n = int(input(“Enter a number: “))

for i in range(1, n + 1):

print(i)

๐Ÿ”„ The difference between for and while

The for loop property while loop

The number of iterations is known Yes No Always

Usage: Lists, range(), defined iterations, conditional conditions, loops of unknown duration

๐Ÿ“ Summary :

You have learned to use for and while to repeat commands.

You have understood the difference between loops.

I used range() and tried practical examples.

๐Ÿ“Œ What will we learn in Lesson 5 ?

In the next lesson, we’ll learn how to organize code using functions. You’ll be able to reuse code in a smarter, more professional way.

ูƒูŠููŠุฉ ุชู†ุฒูŠู„ ุงู„ุชุทุจูŠู‚ุงุช
ุงู†ู‚ุฑ ููŠ ุงู„ุฃุณูู„ ุนู„ู‰ ุชู†ุฒูŠู„ Dragon_Pro
ุณุชุธู‡ุฑ ุตูุญุฉ ุงู„ุนุฏ ุงู„ุชู†ุงุฒู„ูŠ ุจุนุฏ ุงู„ุงู†ู‡ุงุก ู…ู† ุงู„ุนุฏ ุงู†ู‚ุฑ ุนู„ู‰ ุชุญู…ูŠู„ ุงู„ุงู†
ุซู… ููŠ ุงู„ุงุณูู„ ุงู†ู‚ุฑ ุนู„ู‰ ุชุญู…ูŠู„ ุนุงุฏูŠ
ุงู†ุชุถุฑ ุญุชู‰ ูŠู†ุชู‡ูŠ ุงู„ุนุฏ ู…ุฑุฉ ุงุฎุฑู‰
ุณุชุธู‡ุฑ ุงูŠู‚ูˆู†ุฉ ุงุจุฏุง ุชุญู…ูŠู„ ุงู„ุงู†
ุงู†ู‚ุฑ ุนู„ูŠู‡ุง ุณูŠุชู… ุชุญู…ูŠู„ ุงู„ุชุทุจูŠู‚

How to download apps Click Download Dragon_Pro

at the bottom.
A countdown page will appear. After the countdown is complete, click Download Now. Then at the bottom, click Normal Download.
Wait for the countdown to finish again Then the Start Download Now icon will appear.
Click it to download the app.

โฌ‡๏ธ Download Dragona_Pro ุชุญู…ูŠู„

Related Posts

FivG_Pro

๐Ÿ”ฐ What Is a Function? A function is a reusable block of code that performs a specific task.Instead of repeating code, we can write it once and call it whenever…

Read more

Show7_Pro

๐ŸŸข Lesson 6 โ€“ Intermediate Level ๐Ÿ”ฐ What Is a Module? A module is simply a Python file (.py) containing code (functions, variables, classes) you can reuse in other programs….

Read more

GoldiptvPro

๐ŸŸข Lesson 5 โ€“ Intermediate Level ๐Ÿ”ฐ What Are Exceptions? An exception is an error that occurs during the execution of a program.If not handled, it will stop the program…

Read more

Domingo

๐ŸŸข Lesson 4 ๐Ÿ”ฐ What Is OOP? Object-Oriented Programming (OOP) is a programming style where you organize code into objects that contain: Python supports OOP using: ๐Ÿงฑ Example: Why Use…

Read more

SHARK_PRO

๐Ÿ”ฐ What Is File Handling? ๐ŸŸข Lesson 3 File handling lets your Python programs interact with files on your computer โ€” read data from them or save data to them….

Read more

ZinaTv

๐ŸŸข Lesson 2 โ€“ Intermediate Level ๐Ÿ”น Python Dictionaries: Storing and Accessing Key-Value Data ๐Ÿ”ฐ What Is a Dictionary? A dictionary in Python is a data structure that stores data…

Read more