Skip to content
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

Conceptual explanation of Loops #420

Open
delphios opened this issue Oct 25, 2017 · 2 comments
Open

Conceptual explanation of Loops #420

delphios opened this issue Oct 25, 2017 · 2 comments

Comments

@delphios
Copy link

This pertains to the section about Repeating Actions with Loops.

Some of the logic does not appear to follow: we first show indexing of particular elements, i.e. word[0], word[1]..., but do not use actual indices in loops. It would be helpful to show looping both ways, both for char in word and for x in xrange. This would also serve as a conceptual link to the enumerate section at the end.

@cleary3
Copy link
Contributor

cleary3 commented Dec 13, 2017

If explicit ranges were to be added to the lesson, for x in range would be more appropriate than for x in xrange. The Software Carpentry Python lessons are based on Python 3 (in which xrange is deprecated).

Even so, the transition from word[0], word[1], etc., to loops isn't much of a leap, given the included diagram that pictorially shows how the loop over a string selects each character in sequence.

@rgaiacs
Copy link
Contributor

rgaiacs commented Dec 13, 2017

The motivation to not include

for i in range(x):
    foo(x[i])

in the lesson is that it can be seeing as a bad practice, at least in Python. Learners with experience in other languages, e.g. C and Fortran, could decide to always do for i in range(x) instead of for item in x due their similarity with C/Fortran.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants