For One And All


#1

Hello,

I am looking for further explanation about how loops work. The given information is:

A variable name follows the for keyword; it will be assigned the value of each list item in turn.

Then in list_name designates list_name as the list the loop will work on. The line ends with a colon (:slight_smile: and the indented code that follows it will be executed once per item in the list.

I used the hint to figure out the code, but I feel like I missed the concept and the hint just gave an answer.


#2

Let's say the list you are working on has 4 items.

list = ["a", "b", "c","d"]

And your loop is as follows

for letter in list
    print letter

The loop goes over every item in the list and stores the value in the designated variable (in this case, "letter"). So it says: "store 'a' in letter, print it." Next iteration "store 'b' in letter, print it" all the way till it has run the code for every item in the list you designated.


#3

Thank You! That makes more sense.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.