When I see it in practice I’m like yes I get it. But when it’s actually time to read an example then code it with out help my brain just turns to mush like I can’t come up with the code to do the loop
What helped me is to think about the logic for a solving a small instance of the problem without loops. Then you can look for repeated code and decompose it into functions. After that, it's easier to see the parts that can be generalized to solve for an arbitrary instance. Wrap those functions in a loop to make the general solution :)
reply
I think of it more like a merry-go-round and each statement is sort of like your position as you go around. At some point the ride stops (you exit the loop), and you get on another ride.
reply