Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Python Loops Complete Guide | For + While + Nested | 20 Examples | Grade 9-12

Rating
-
Sold
-
Pages
6
Uploaded on
22-04-2026
Written in
2025/2026

Complete Python loops guide for beginners. Covers For Loop, While Loop, Nested Loops with 20 solved examples and exam cheat sheet. 10 Pages PDF. Perfect for Grade 9-12 Computer Science. Includes theory, code, output, and common errors. 100% Exam Ready.

Show more Read less
Institution
Course

Content preview

Python Loops: Theory + Code Complete Guide

For Loop, While Loop, Nested Loops | 20 Examples with Explanation

Grade 9-12 | Computer Science | 100% Exam Ready



---



PAGE 1: WHAT IS A LOOP? - THEORY



Definition:

A loop is a programming tool that repeats a block of code multiple times without writing it again and
again.



Real Life Example:

If you need to write "I will complete my homework" 100 times, you won't write it by hand 100 times. A
loop is your robot that does it in 2 seconds.



Types of Loops in Python:

1. for loop → Used when you know "how many times" to repeat. Example: Count from 1 to 100.

2. while loop → Used when you know "until when" to repeat. Example: Keep asking for password until
correct.



---



PAGE 2-4: FOR LOOP - THEORY + CODE



Theory:

A for loop is used when the number of repetitions is fixed. It iterates over each item of a sequence like
list, string, or range() one by one.



Basic Code Structure:

, for variable in sequence:

# code to repeat

# Indentation of 4 spaces is mandatory



Example 1: Print 0 to 4

for i in range(5):

print(i)

Output:

0

1

2

3

4

Explanation: range(5) creates the sequence 0,1,2,3,4. 'i' takes each value one by one.



Example 2: Table of 2 from 1 to 10

for num in range(1, 11):

print("2 x", num, "=", 2 * num)

Output: Prints the table of 2 from 1 to 10



Example 3: Print items of a list

names = ["Ali", "Asha", "Ahmed"]

for student in names:

print("Hello", student)

Output:

Hello Ali

Hello Asha

Hello Ahmed

Written for

Institution
Secondary school
School year
4

Document information

Uploaded on
April 22, 2026
Number of pages
6
Written in
2025/2026
Type
SUMMARY

Subjects

$10.69
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
marianoor1

Also available in package deal

Get to know the seller

Seller avatar
marianoor1 Government College university, Faisalabad
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 months
Number of followers
0
Documents
13
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions