python-socialsci icon indicating copy to clipboard operation
python-socialsci copied to clipboard

while vs for loops?

Open brownsarahm opened this issue 7 years ago • 2 comments

Is there a reason to introduce while loops beofore for loops? There is also more content on while loops than for loops. I think for loops are more common; while loops may not even be necessary.

brownsarahm avatar Jun 15 '18 03:06 brownsarahm

With while loops, you can see each of the initialization, stopping condition, and iterative step separately in 3 different lines. Because of this, you can explain the concept of loops more easily in a way that your users can grasp. Then, after the students understand the concept of a while loop, you can introduce the for loop and show that it is a more concise way of doing a while loop.

diniangela avatar Jul 22 '19 23:07 diniangela

But so many errors are possible with while loops. I think for loops have training wheels and while loops are more flexible. I agree that for loops should go first.

eldobbins avatar Nov 29 '20 18:11 eldobbins