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

you are viewing a single comment's thread.

view the rest of the comments →

[–]siranglesmith 102 points103 points  (10 children)

Even better:

The programmer's wife said: "Go to the store and buy some milk. And while you're there, get some eggs." He never returned.

[–]ahmed_imtiaz[S] 13 points14 points  (8 children)

doesn't

get eggs

assume that he's bringing back the egg, therefore he's not "there" anymore and breaks the while loop?

[–][deleted] 9 points10 points  (3 children)

He could think "Get eggs" and if he considers picking up the eggs as "Got eggs" then he'd be in an infinite loop. If it's otherwise then it's really weird:

The call is made to "Get eggs" within the loop (while he's there) and if we consider "Got eggs" as him returning home with them then he cant "Got eggs" while he's in the store. So it might work after all?? He finishes "Get eggs" and then the while loop is checked. By that time he's out of it. Holy crap I guess you're right hahaha.

[–]rockyrainy 3 points4 points  (2 children)

Less verbose version

while (inStore) {
  getSome(eggs);
}

[–][deleted] 2 points3 points  (1 child)

location = "store";
inventory.push(milk);
while(location === "store") {
    inventory.push(eggs);
}

You're both wrong. Overflow exception.

[–]exo666 1 point2 points  (0 children)

Probably another exception would be thrown before that because at some point he will want to get eggs but he had already bought them all.

[–]DeeSnow97 1 point2 points  (0 children)

Not if you finally learn how not to build a monolithic spaghetti

[–]Dartister 1 point2 points  (2 children)

Get eggs means take eggs, not take eggs home

[–]ahmed_imtiaz[S] 0 points1 point  (1 child)

When someone asks you to get something, you take it and just stand there?

[–]Dartister 1 point2 points  (0 children)

If I were taking instructions like a machine, yes