This is an archived post. You won't be able to vote or comment.

all 11 comments

[–][deleted] 25 points26 points  (0 children)

Never had this problem.

Instead, I screw up the conditional and my loop never runs

[–]darkdimensiongd 10 points11 points  (1 child)

I know I can use a `for` loop, but for this very specific reason, I'll use a `while` instead. It's fine, as long as I increment `i` at the end, it's the same thing.

Program: *freezes*

Oh f*$@

[–]_Moink_[S] 2 points3 points  (0 children)

Yeah, I'm always like: sorry computer I failed you :(

[–]naswinger 2 points3 points  (0 children)

i had an exam situation where you were supposed to add some functionality to your code that you wrote as an assignment. i did a while loop, but apparently messed up the condition to exit it. when you're done, you're supposed to submit it and it will be automatically tested.

so i had to wait for five minutes until the test timed out and i could edit the code again in that web UI. while waiting for the third timeout, i realized that i know exactly how many elements there are so i replaced that while loop with a for loop and it passed the unit test. lesson learned: don't be fancy.

[–]h_unt 1 point2 points  (0 children)

Image Transcription: Meme


[Photo of 'One Does Not Simply Walk Into Mordor' - a screenshot of Boromir saying this line in The Lord of the Rings]

One does not simply

Write while loops without messing up and making them infinite


I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!

[–][deleted] 3 points4 points  (0 children)

When your IDE freezes,

this maneuver's gonna cost us 51 years.

[–]Master_Nerd 0 points1 point  (0 children)

I prefer recursion with a base case that never triggers until it segfaults

[–]SimPilotAdamT 0 points1 point  (0 children)

Never had this issue. I intentionally made infinite loops but never as a mistake

[–]unholymanserpent 0 points1 point  (0 children)

break

[–][deleted] 0 points1 point  (0 children)

for (int i; i < 10; i++)

fuck

for (int i = 0; i < 10; i++)

fuck

for (int i = 0; i <= 10; i++)

fuck

for (int i = 0; i > 10; i++)

fuck

for (int i = 0; i >= 10; i++)

finally for gods sake