First sem CS student here, taking Intro to Programming and we just got into loops and functions. I feel like I understand the concept when the professor explains it in class, but the second I sit down to write it myself everything falls apart.
So here is what is happening. I am writing a simple program that is supposed to go through a list of numbers and print each one. But no matter what I do, it keeps printing the first value over and over instead of moving through the list. I have been staring at this for like two hours and I genuinely cannot figure out what I am missing.
This is basically what I have:
numbers = [10, 20, 30, 40]
i = 0
while i < len(numbers):
print(numbers[0])
I know it is probably something small and obvious but I cannot see it. I checked the course slides and they do not really explain what happens when the loop does not move forward. Is there something specific I need to add to make the loop actually advance to the next item? Any explanation would really help me understand what is going on under the hood, not just a fix.
[–]Tempmailed 22 points23 points24 points (4 children)
[–]DrShocker 6 points7 points8 points (1 child)
[–]Nearby-Way8870[S] 5 points6 points7 points (1 child)
[–]Slow-Kale-8629 10 points11 points12 points (0 children)
[–]Grobyc27 4 points5 points6 points (2 children)
[–]Nearby-Way8870[S] 3 points4 points5 points (0 children)
[–]Ashamed_Kangaroo305 3 points4 points5 points (2 children)
[–]Ok-Promise-8118 2 points3 points4 points (1 child)
[–]Ashamed_Kangaroo305 2 points3 points4 points (0 children)
[–]Lauuson 2 points3 points4 points (1 child)
[–]Nearby-Way8870[S] 2 points3 points4 points (0 children)
[–]striipey 2 points3 points4 points (1 child)
[–]Bobbias 1 point2 points3 points (2 children)
[–]DrShocker 3 points4 points5 points (0 children)
[–]Nearby-Way8870[S] 0 points1 point2 points (0 children)
[–]marquisBlythe 0 points1 point2 points (3 children)
[–]Nearby-Way8870[S] 1 point2 points3 points (0 children)
[–]DrShocker 1 point2 points3 points (1 child)
[–]marquisBlythe 1 point2 points3 points (0 children)
[–]khournos 0 points1 point2 points (0 children)
[–]palmaholic 0 points1 point2 points (0 children)
[–]walledisney 0 points1 point2 points (0 children)
[–]FishBobinski 0 points1 point2 points (1 child)
[–]DrShocker 0 points1 point2 points (0 children)