T
13

I was writing my loops backwards for a month

Honestly, I was working on a small project in Python last week, trying to print numbers from 1 to 10. I kept writing 'for i in range(10, 0, -1)' and wondering why it started at 10. A friend looked at my screen and just said 'Dude, you have the start and stop swapped.' I felt so dumb, but it finally clicked that range(1, 11) gives you 1 through 10. Has anyone else mixed up the order in a loop like that?
2 comments

Log in to join the discussion

Log In
2 Comments
bell.emma
bell.emma25m ago
My brain always defaulted to the start number being bigger than the end. It just made sense to me that you count down from something. Seeing the correct order in a real script was a real forehead-slapping moment. The logic finally landed when I pictured it as "start here, stop before this." Now it seems obvious, but it took seeing it wrong to get it right.
6
the_ryan
the_ryan3h ago
Classic range brain freeze. Been there, stared at that exact same backwards output for way too long.
3