Skip to content

Commit b693e47

Browse files
committed
Sample code to understand While-loops in python
1 parent 4d77cc4 commit b693e47

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

samplewhile.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# A while-loop will keep executing the code block under it as long as a boolean expression is True.
2+
# If we write a line and end it with a colon then that tells Python to start a new block of code.
3+
# Then we indent and that is the new code.
4+
# This is all about structuring your programs so that Python knows what you mean.
5+
# If you do not get that idea then go back and do some more work with if-statements, functions, and the for-loop until you get it.
6+
7+
# SAMPLE CODE
8+
9+
i = 0
10+
numbers = []
11+
while i < 6:
12+
print "At the top i is %d" % i
13+
numbers.append(i)
14+
i = i + 1
15+
print "Numbers now: ", numbers
16+
print "At the bottom i is %d" % i
17+
print "The numbers: "
18+
for num in numbers:
19+
print num

0 commit comments

Comments
 (0)