-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path042-For-Loop.py
More file actions
50 lines (41 loc) · 1.54 KB
/
Copy path042-For-Loop.py
File metadata and controls
50 lines (41 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
===============================================================================
For Loop
===============================================================================
Program Description:
--------------------
This program demonstrates the use of the for loop in Python.
The for loop is used to execute a block of code repeatedly for each item
in a sequence. In this example, the range() function is used to generate
numbers from 1 to 5.
Syntax:
for variable in sequence:
statements
Author : Shaik Mahaboob Basha
Repository : 13-Python
File Name : 42-For-Loop.py
===============================================================================
"""
# -----------------------------------------------------------------------------
# Displaying a heading.
# -----------------------------------------------------------------------------
print("Numbers from 1 to 5")
# Output: Numbers from 1 to 5
# -----------------------------------------------------------------------------
# Using the for loop to display numbers from 1 to 5.
# -----------------------------------------------------------------------------
for number in range(1, 6):
# The loop variable stores one value at a time.
print(number)
# Output:
# 1
# 2
# 3
# 4
# 5
# -----------------------------------------------------------------------------
# Displaying a message after the for loop.
# -----------------------------------------------------------------------------
print("Program Completed.")
# Output:
# Program Completed.