-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path043-While-Loop.py
More file actions
61 lines (50 loc) · 2 KB
/
Copy path043-While-Loop.py
File metadata and controls
61 lines (50 loc) · 2 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
51
52
53
54
55
56
57
58
59
60
61
"""
===============================================================================
While Loop
===============================================================================
Program Description:
--------------------
This program demonstrates the use of the while loop in Python.
The while loop is used to execute a block of code repeatedly as long as
the given condition is True.
Syntax:
while condition:
statements
Author : Shaik Mahaboob Basha
Repository : 13-Python
File Name : 43-While-Loop.py
===============================================================================
"""
# -----------------------------------------------------------------------------
# Creating a variable with the starting value.
# -----------------------------------------------------------------------------
number = 1
# number stores the starting value 1.
# -----------------------------------------------------------------------------
# Displaying a heading.
# -----------------------------------------------------------------------------
print("Numbers from 1 to 5")
# Output: Numbers from 1 to 5
# -----------------------------------------------------------------------------
# Using the while loop to display numbers from 1 to 5.
# -----------------------------------------------------------------------------
while number <= 5:
# Displaying the current value of the variable.
print(number)
# Output:
# 1
# 2
# 3
# 4
# 5
# -------------------------------------------------------------------------
# Increasing the value of the variable by 1.
# -------------------------------------------------------------------------
number = number + 1
# The value of number increases after each iteration.
# -----------------------------------------------------------------------------
# Displaying a message after the while loop.
# -----------------------------------------------------------------------------
print("Program Completed.")
# Output:
# Program Completed.