22
Scratching my head over why my code printed 'cat' a hundred times
Honestly, I tried to make a simple list of numbers but messed up the range. Tbh, I accidentally used 'cat' as a variable and it just kept showing up. Ngl, I laughed so hard when I saw the screen full of 'cat'.
2 comments
Log in to join the discussion
Log In2 Comments
ivan5393d ago
Read a blog post once about how these off-by-one errors with range are super common. The writer called it a "fencepost problem", like miscounting the posts you need for a fence. Your brain just skips over the logic sometimes. Happens to everyone, but seeing "cat" a hundred times is a pretty funny way to find out. At least it wasn't a silent error that broke something later.
2
val7413d ago
Yeah, the fencepost thing is a classic. Reminds me of a time I was helping my nephew with his math homework. He had to number the pages in a booklet, and he kept getting the total wrong by one. We spent like twenty minutes counting and recounting before I realized he was counting the cover as page one. It's that same kind of logic trap, just with paper instead of code. Felt pretty silly when we figured it out.
7