125
u/SkindianaBones98 Jun 28 '25
Unless they both started on the edge of the cliff where roadrunner is, these loops should have the same result
63
u/Gogo202 Jun 28 '25
OP is still in their first semester, so they don't have programming experience yet
0
Jun 29 '25
[deleted]
20
u/buildmine10 Jun 29 '25 edited Jun 29 '25
A do while loop does the first iteration without the check. Subsequent iteration ls get the check. So unless they start running on the edge, the check will fail before running off the edge.
The meme doesn't show an understanding of this fact, since the roadrunner and coyote have usually been running for a while before this happens. This meme often receives this exact criticism. That is why they concluded that you are inexperienced.
The correct checks to get this behavior are "while not edge" and "while grounded".
0
Jun 29 '25
[deleted]
6
u/Kim-Meow-Un Jun 29 '25 edited Jun 29 '25
I'm confused, is this is a very complicated way of saying that they're both starting from the edge of the cliff? šThat doesn't make sense.
3
u/OkMemeTranslator Jun 29 '25
Why do you talk like this? It doesn't make you look intelligent, it makes you look stupid for not being capable of expressing yourself in a way that others would understand.
Literally all you said was "the program execution started when they were already on the edge" which is what the other person said already. Which kind of makes the meme okay, but in the TV show they definitely don't both start on the edge. So not that good after all.
1
u/buildmine10 Jun 29 '25 edited Jun 29 '25
If interpreted that way, then it does make for a good example of how a do while loop could fail. It's the external context of the cartoon, however, that makes this interpretation unlikely unless explained as you just have. That is why this meme is regularly critiqued nearly every time it is posted.
Additionally, I don't believe I provided an insult in my explanation (I'm not even certain you are saying I provided an insult. It's also possible that you did not like my explanation of other's behavior. Unfortunately, I don't have a better explanation to give you.). I explained the difference between a do while loop and a while loop in case you were unaware. I explained why the previous comment had declared you inexperienced. And I provided an example that would have the observed effect in the scenario that most people are primed to think of.
I believe I know why you might have interpreted it as an insult. I would appreciate feedback as for how to provide the explanation I wrote in a way that would not be interpreted as an insult.
Edit: I just realized another reason that actually makes your interpretation a pun. Your interpretation is an edge case. I wonder if this visual pun was intended by the original creator of the meme.
1
7
1
u/jacob643 Jun 28 '25
I think a more accurate meme would have something like this:
for(int i= 0; i < list.size(); i++) console.log(list[I]);
for(int i= 0; i <= list.size(); i++) console.log(list[I]);
1
u/buildmine10 Jun 29 '25
This works as an analogy where running off the cliff is a buffer overflow.
2
u/jacob643 Jun 29 '25
right, so a better option would be:
while(isEdgeAt(GetPos())) { TakeStep(); }
vs
while(IsEdgeAt(GetPos()+Steplenght())) { TakeStep(); }
so checking under the character.
edit: but now, it's not a common programming error trope anymore, idk if there's a clean and accurate way to make the mĆŖme related to the classic off by one error
1
1
0
7
Jun 29 '25
Got bad news for you, unless you only start at the edge, these will both run off of the edge (or not run off the edge, depending on how edge is defined).
1
u/Amr_Rahmy Jun 30 '25
While(true){
Run();
If (!onSolidGround){
realizeTheErrorOfYourMistake();
fall(); break;
}
}
4
3
u/Ronin-s_Spirit Jun 28 '25
I remember I had exactly one case where I needed to use a do..while, something to do with parallel processing of matrices where I knew at least 1 thread must be tasked no matter what.
1
u/Andr0NiX Jun 28 '25
Well that would be the first time i found a valid use for them other than input taking lol
1
u/Ronin-s_Spirit Jun 28 '25
I had a math matrix constructor that would throw if you gave it 0 rows and columns, so I was always sure that a matrix is not empty.
What about input taking, what do you mean by that?2
u/Andr0NiX Jun 28 '25
Neat!
Basically, I meant something like this
do { x = input(prompt) } while (x is not valid)0
Jun 28 '25
[deleted]
1
u/Puzzleheaded_Study17 Jun 29 '25
This is primarily for when there's no initial input, for example when getting input from a user
1
u/buildmine10 Jun 29 '25
That is still what you do. You have to get the input then validate it, then reprompt if invalid. Even with html forms this is what happens. If the first input is invalid then the while loop check will trigger and it will prompt again
1
u/Andr0NiX Jun 30 '25
What did they say?
1
u/buildmine10 Jun 30 '25
Basically that "if you are given invalid input on the first iteration, then the code will fail to have the correct behavior". Which is false. A do while loop correctly catches invalid inputs on the first attempt.
1
u/Amr_Rahmy Jun 30 '25
Maybe you are still young?
I didnāt use them until later in my career but now I use them more.
Definitely use do while when trying to paginate or poll information to sync things from an api or any source when you donāt know the count beforehand.
Anything you do on a regular basis that you paginate or split up.
2
4
u/tecanec Jun 28 '25
I have two things to say:
First, this is inaccurate. Both should behave the same unless they start at the cliff. The difference between "while" and "do while" is that the later skils the check for the first iteration, so "do while" is guaranteed at least one iteration whereas "while" will have zero iterations if the condition is false at the beginning.
Second... let's just say this isn't the first time I've been saying that about this image here on Reddit.
2
u/a_aniq Jun 29 '25
Doesn't seem right. Road runner should also fall because it hasn't reached edge yet.
3
u/navetzz Jun 28 '25
STOP ALREADY WITH THIS SHIT. ITS NOT EVEN REMOTELY CLOSE TO TRUE.
This meme belongs in r/programminghorror
1
1
u/MrMurpleqwerty Jun 30 '25
technically wile e, should keep running since he's not at the edge of the cliff
1
1
1
1
u/Morthem Jul 09 '25
There are two hard things in programming: Cache invalidation, naming things, and off by one errors
1
u/ksschank Jul 12 '25
Poorly named variables. Roadrunner is just as close to the edge as Wile E. Coyote. And donāt put ānotā at the beginning of a variable nameāname for the positive case. e.g. Instead of notEdge, use pastEdge or !pastEdge.
1
u/magicman_coding Jun 28 '25
I see 2 while not edge runs...just one came at the situation with the wrong velocity
15
u/doc720 Jun 28 '25
I'm curious how
edgeandrunare defined.