While Loops vs For Loops
Two Kinds of Loops …
Let's Try Using Both…
count to 0 to 25 by 5's
implement using while
implement using for
print out a series of numbers, each randomly chosen from (1 through 10) that add up to 50 (you can go over)
implement using while
implement using for
For Loops…
When should you use them? →
you know ahead of time how many iterations you'll have to go through
you have an
iterable
structure that you have to traverse
a sequence of numbers
a list of
items
While Loops
When should you use them? →
when you don't know how many iterations you'll have to go through!
when you must repeat something until some condition is met
generally not a great option for counting (need to keep track of counter separately)
Some Exercises