Skip to content

Commit 763c726

Browse files
authored
While loop example
Breaking out of a while loop early. Code example prints out first five (or less) test scores.
1 parent 30b6d8c commit 763c726

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Use case 2: Print out the score of the first five tests (while loop)
2+
scores = [90, 30, 50]
3+
i = 0
4+
5+
while i < 5:
6+
if i > len(scores) - 1:
7+
# If there are less than 5 scores, break out of the loop when all scores are printed
8+
break
9+
print("Score: " + str(scores[i]))
10+
i += 1

0 commit comments

Comments
 (0)