New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode 2: Clarify loop variable need not appear within loop itself #512

Open
jjocemac opened this Issue May 1, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@jjocemac

jjocemac commented May 1, 2018

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".

@maxim-belkin

This comment has been minimized.

Collaborator

maxim-belkin commented May 4, 2018

Hi @jjocemac

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.

@jjocemac

This comment has been minimized.

jjocemac commented May 14, 2018

Hi @maxim-belkin,
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?

@maxim-belkin

This comment has been minimized.

Collaborator

maxim-belkin commented May 14, 2018

@jjocemac, because these are related changes, it makes sense to submit them together: we are still able to comment on the individual components of the PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment