0
What is a Counter Variable in for Loops?
This is the code in the lesson: words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: Â Â word = words[counter] Â Â print(word + "!") Â Â counter = counter + 1Â Here I am trying to understand it: while 0 is less than or equal to 3: word equals the list labeled words[0] print(word plus "!") counter = 1 I am not understanding what the counter does
3 Answers
+ 1
Okay thank you, I think I get it
0
Counter is variable you used to count only certain numbers iterations to be done only...
In this example, counter incremented every time one so for value 0 to 3(max_index), loop runs when it is 4,loop stop iterating..
It just user defined variable taken as a counter, so you can use any other variable like i, j, k...
0
Wel come..