You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps we should state explicitly that the loop variable need not always be used within the loop itself?
I have witnessed confusion from learners attempting the 'Computing Powers With Loops' exercise, who assume that the loop variable must appear within the loop, when in fact the solution doesn't require this.
Perhaps the confusion stems from the text that says:
The general form of a loop is:
for variable in collection:
do things with variable
It's not immediately obvious to me how we could modify this statement in a 'nice' way to highlight the caveat that the variable need not be used. Perhaps we could instead add the following text to the paragraph just below the example loop that repeatedly updates the variable 'length':
"Note that a loop variable does not necessarily have to appear within the loop itself, as in the above example, in which the loop variable vowel is assigned but not used"
along with the following 'hint' in the 'Computing Powers With Loops' exercise:
"Write a loop that calculates the same result as 5 ** 3 using multiplication (and without exponentiation). Hint: You don't need to use the loop variable within the loop itself".
The text was updated successfully, but these errors were encountered:
It's not immediately obvious to me how we could modify this statement in a 'nice' way to highlight the caveat that the variable need not be used.
A naive question: how can one print an empty line three times? could lead to a discussion on how loop variable is updated every iteration and about programmer's responsibility to use or not use that variable.
Thanks - this sounds like a good idea. Would you like me to have a go at submitting a PR for this? If so, what about the two edits I also suggested - do you think one/both of these should still be added, or left out?