Day 10: Python Syntax: Basic Concepts — For loops and while loops.

Day 10: Python Syntax: Basic Concepts — For loops and while loops.

Python in 30 Days: A Practical and Theoretical Approach for Beginner.

loop in Python is a way to repeat a block of code multiple times.

For loop repeats the code for each item in a list or a set number of times.

image 38 Simply Creative Minds

Example

Print Hello 3 times example

for i in range(3):
 print("Hello")
image 22 Simply Creative Minds

A while loop repeats code as long as a condition is true.

Same example with while loop

count = 0
while count < 3:
    print("Hello")
    count += 1
image 23 Simply Creative Minds

Advantages of Loops

1 Avoid Repetition-We don’t have to write the same code many times

2. Makes Code Cleaner and Shorter — Loops reduce the number of lines of code, making it easier to read and maintain.

3. Automates Repetitive Tasks — Great for doing the same task again and again — like Sending emails to 100 people , Checking each item in a list

We will discuss the Looping Through Different Data Types in next Day 11 .

Happy Coding and Stay Tuned 🙂

Kind is always cool !!!

Share knowledge to gain knowledge !!!!

Be kind and treat people with respect !!!

If you find my blog helpful, then please subscribe, claps and follow to support 🙂

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *