In this example, the
You can get the same effects with a
Both give same result
for loop
and range(99, 0, -1)
tells the script how many times to loop through something whether it be a word, function, object, etc. beer_num
could be an underscore, letter, or word. There are special characters than can not be used.You can get the same effects with a
while loop
.Both give same result
print('----- for loop -----') for _ in range(10, 0, -1): print(_) bottles = 10 print() print('----- while loop -----') while bottles > 0: print(bottles) bottles -= 1
Output:----- for loop -----
10
9
8
7
6
5
4
3
2
1
----- while loop -----
10
9
8
7
6
5
4
3
2
1
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags