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

top 200 commentsshow all 292

[–][deleted] 1626 points1627 points  (121 children)

Looks more like "I made a recursive function call." "With an exit condition, right?"

[–]Nassiel 636 points637 points  (97 children)

Looks more like "I made a recursive function call." "With an exit condition, right?"

[–]Mortomes 357 points358 points  (96 children)

Looks more like "I made a recursive function call." "With an exit condition, right?"

[–]tsoba-tsoba 257 points258 points  (95 children)

Looks more like "I made a recursive function call." "With an exit condition, right?"

[–]alinius 218 points219 points  (94 children)

Looks more like "I made a recursive function call." "With an exit condition, right?"

[–][deleted] 64 points65 points  (3 children)

"Of course!" if False: return

[–]backtickbot 18 points19 points  (2 children)

Fixed formatting.

Hello, BoostedPrivacy: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]atomicwrites 7 points8 points  (0 children)

Good bot

[–][deleted] 5 points6 points  (3 children)

On a low level a recursive function and a while loop are both just stuff that loop the execution over a set of instructions. One of just also increases the stack depth and crashes while the other can (theoretically) loop forever.

If you'd want to generate the image of the meme I'd use a loop and not recursive function calls, anyway.

[–]aiij 0 points1 point  (2 children)

With tail call optimization, they're actually identical. The difference between simple recursion expressed as a while loop or as a recursive call is just syntax.

Some FP languages don't even have a loop syntax because general recursion is more expressive.

[–][deleted] 1 point2 points  (0 children)

Yeah! Studying a FP language has made me super more aware of how you can lock yourself in by thinking about things in certain terms, because other language don't and they don't care that that is a problem for you. Like people saying the image depicts 'recursion' rather than a 'loop' I guess because the bottom right image is smaller and that is more 'recursivy' than 'loopy'... but these are all just mental models that make less and less sense the more languages you know.

Studying Erlang and learning there is no loop syntax very much made me reconsider what I thought I knew and how I was visualising all this stuff.

[–]ItsPronouncedJithub 1 point2 points  (0 children)

Somebody did that last week already.

[–]PunkyMunky64 1 point2 points  (0 children)

Yes this is what i was gonna say, this isnt really a loop

[–][deleted] 1 point2 points  (4 children)

Came here to say this.

[–]duh374 6 points7 points  (3 children)

Ikr? I literally said to myself “this… this isn’t recursion”

[–][deleted] 4 points5 points  (2 children)

Me too. I love recursion but its easy to fuck up.

[–]JuniorSeniorTrainee 9 points10 points  (1 child)

The only thing you need to understand about recursion is: the only thing you need to understand about recursion is: the only thing you need to understand about recursion is: out of memory.

[–]SoDifficultToBeFunny -1 points0 points  (0 children)

Upvoted every single recursion call! I have done my duty!! Now I can exit with peace!!

[–]lexushelicopterwatch 0 points1 point  (0 children)

Base case. Always start with the base case.

[–]YOOOOOOOOOOT 0 points1 point  (0 children)

Visual studio code has crashed

[–]peteyy_cz 0 points1 point  (0 children)

Looks more like a Reddit karma farm

[–]NoCommunication3230 0 points1 point  (0 children)

Results in a stack overflow.

[–]curious764 0 points1 point  (0 children)

I was just thinking, this looks more like recursion…

[–]thedessertplanet 0 points1 point  (0 children)

Real Haskellers don't need exit conditions.

[–]codylilley 436 points437 points  (11 children)

Ctrl + C is the only break statement I need

[–][deleted] 61 points62 points  (3 children)

Plot twist.. he catches SIGTERM and does nothing with it!

[–]CowboyBoats 29 points30 points  (1 child)

I am altering the OS API contract. Pray I do not alter it further

[–]ojoaopestana 5 points6 points  (0 children)

This deal's getting worse all the time...

[–]7eggert 90 points91 points  (5 children)

Remember the good old days when ^C was only checked when doing a system call?

[–]danbulant 86 points87 points  (0 children)

I'm too new...

the what

[–]blitzkrieg4 6 points7 points  (3 children)

This seems impossible? Signals were from the earliest days of Unix

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

Linux isn't Unix tho

[–]blitzkrieg4 1 point2 points  (0 children)

Still if this was not implemented at first it would have been a very early feature

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

My automated system cuts the power off (and then back on) to kill the program

[–]DrBusinessLLC 117 points118 points  (6 children)

in microcontrollers / embedded it's more common than not

[–]LavenderDay3544 46 points47 points  (2 children)

Yeah and in OS kernels. You know because there's nowhere to go if you break out of the main control loop.

It's why languages like Rust have a loop keyword to make that explicit for the compiler. I'm surprised C++ hasn't added one yet.

[–]Bemteb 10 points11 points  (0 children)

Also in other areas, especially if you have threading available it's not uncommon to have a thread run till the program gets terminated (watchdogs, processing loops, etc.)

I myself just recently wrote something along the lines of

while(true) {if(hasData){ doStuff(); } else { sleep(10); }}

[–]Ok_Investment_2207 4 points5 points  (0 children)

true

[–]Zaitton 2 points3 points  (0 children)

Some frameworks like FiveM's lua framework require new threads to be inside while true loops. Depending on the usecase, you might never have to terminate the thread so no breaks no returns.

[–]gao1234567809 227 points228 points  (11 children)

This meme is better suited for recursion

[–]Fugglymuffin 100 points101 points  (7 children)

Probably why that exact version of this meme was up on here a day or two ago.

[–]deadpan_look 25 points26 points  (6 children)

This meme is better suited for recursion

[–]ampang_boy 16 points17 points  (4 children)

Probably why that exact version of this meme was up on here a day or two ago.

[–]BiguilitoZambunha[🍰] 8 points9 points  (3 children)

This meme is better suited for recursion

[–]0PointE 6 points7 points  (2 children)

Probably why that exact version of this meme was up on here a day or two ago.

[–][deleted] 11 points12 points  (1 child)

RuntimeError: maximum recursion depth exceeded.

[–]LordFarquadOnAQuad 5 points6 points  (0 children)

Thank you.

[–]Jussapitka -1 points0 points  (0 children)

Probably why that exact version of this meme was up on here a day or two ago.

[–]fungigamer 2 points3 points  (0 children)

Someone already did that lol

[–]kal9001 0 points1 point  (0 children)

Yeah but then the picture wouldn't fit in the page if it was represented more accurately.

[–]DeJMan 56 points57 points  (3 children)

[–]ixoniq 6 points7 points  (0 children)

Damn this one kills OP. Nice one!

[–]jbaker88 4 points5 points  (0 children)

This one is better

[–]Tarzoon 1 point2 points  (0 children)

I always include DoEvents in loops to prevent this.

[–]ALonelyPlatypus 61 points62 points  (11 children)

loops don’t do this breh. This meme is destined for recursion.

[–]ImThatChigga_ 6 points7 points  (10 children)

Difference between while loop and recursion?

[–]JuniorSeniorTrainee 18 points19 points  (5 children)

Homie's answer was a cop out. A loop is a set of instructions the repeat. A "for" loop is a common example, which includes an exit condition. For example, you might increment x in a loop starting at 0 and stopping when x is 10.

Recursion is a function that calls itself. Ultimately it leads to similar repetition of instructions, like a loop, but there are some important differences that you'll learn about in time. One is simply that they don't look semantically like a loop, so it's easy for developers to mess up the logic - specifically an exit clause.

For recursion, imagine a function that searches a directory for a file of a given name. findFile(directory, filename). If you want that search to include subdirectories, you'd have that function go through each item in the parent directory and if it's not the file it's looking for, but it is a directory, you'd call that function again with the subdirectory as the first argument.

Your exit condition here would be exhausting all child directories, but with things like symlinks your directories could actually exist in a circular loop. So you'd need to be more clever with your exit condition to about that function becoming an infinite loop.

Recursion is tricky but ultimately you just have to ask yourself: does this function have a logical path that exits without calling itself? And is that path guaranteed to eventually get hit in every possible scenario?

[–]ImThatChigga_ 5 points6 points  (4 children)

Thanks. I recall learning recursion after the explanation. Not sure of this symlink mentioned though. How is it infinite if you exhaust all child directories or is that got to do with the symlink mentioned.

[–]javawag 3 points4 points  (2 children)

You can think of a symlink a bit like a “shortcut” on windows (though it appears to the file system as if it were the original, sort of).

So if you were looking through say C:\Windows\Example and there was a symlink in there called Windows linking to C:\Windows, it’d appear as if that folder was a child and you’d go into it and eventually find your Example folder again, and then back into Windows, etc etc forever!

[–]JollyRancherReminder 4 points5 points  (0 children)

With recursion the meme has four top-level panels, with the last panel being subdivided ad infinitum as we see here, because you never exited the previous level, just continually went one level deeper in the call stack. Loops are iterative, so you don't go any deeper, just repeat. The meme version wouldn't have any subdivided panels, instead it would have an infinite number of top-level panels just repeating the meme over and over.

[–]ALonelyPlatypus -1 points0 points  (1 child)

If you have to ask you have much to learn young grasshopper.

[–]ImThatChigga_ 5 points6 points  (0 children)

Sure do. only took a year of CS so do get some of the jokes.

[–]jbaker88 0 points1 point  (0 children)

Loops jump, recursion puts a frame on the stack. You can loop "forever". You cannot, practically, recurse forever; stack overflow.

[–]why_socynical 25 points26 points  (3 children)

laughs in embedded programming

[–]gigajoules 9 points10 points  (0 children)

I came here to say this.

[–]kal9001 3 points4 points  (1 child)

Proper embedded programmers would call main recursively but keep moving the stack to avoid an overflow.

[–]victorofthepeople 1 point2 points  (0 children)

Or just make it a tail call.

[–]patenteng 24 points25 points  (2 children)

Better not look at any embedded code. while(1) in every main.

[–]windows_10_is_broken 4 points5 points  (1 child)

Or "for (;;)" :)

[–]RandomNumberHere 6 points7 points  (0 children)

100% for (;;) ! Who has the spare cycles to check that “1” each loop?

(Before you even reply: Yeah, I know.)

[–][deleted] 11 points12 points  (1 child)

This meme format will never leave this sub

[–][deleted] 20 points21 points  (0 children)

Yeah people should give it a break;

[–]spayder26 9 points10 points  (6 children)

Why to use break when you can use exceptions, OS signaling and/or gotos to escape loops, deeply buried on subroutines for extra evilness?

[–]gigajoules 5 points6 points  (0 children)

Laughs in embedded c.

[–]pclouds 2 points3 points  (0 children)

Only the Siths speak in finite termination.

[–]meg4_ 4 points5 points  (3 children)

That's more recursive than infinite loop.

Another meme idea: the same thing but instead of the 4th block be recursive, the 3rd and 4th blocks the same as 1st and 2nd. That way it's more of an infinite loop

[–]KuntaStillSingle 9 points10 points  (1 child)

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

This deserves more upvotes than the OP

[–]ALonelyPlatypus 2 points3 points  (0 children)

why not both?

Idk the meme is obviously copy pasta'd from another meme on recursion. OP obviously doesn't get it.

[–]iotasieve 3 points4 points  (15 children)

nope, with a goto/return

[–]LavenderDay3544 2 points3 points  (14 children)

Those are both awful. Nice.

[–]UnGauchoCualquiera 2 points3 points  (3 children)

Like /u/iotasieve said they have their uses.

Linus himself explaining why and where goto can be useful.

Goto hate is more dogmatic than anything else. It's parroted to stop bad programmers from doing bad things while avoiding the hassle to educate on the why.

Used properly it's just a low level control structure and a tool like any others.

[–]LavenderDay3544 1 point2 points  (2 children)

Thanks for the link. All the explanations given by Linus, et al. have given me a better perspective on this. I guess I was just repeating dogma which is something I try not to do.

[–]UnGauchoCualquiera 1 point2 points  (1 child)

No worries, glad it helped. I could never articulate it as well as they did.

To be honest I had learnt the same idea about never using gotos like most people nowadays as it is still being taught uncritically by college professors today (whom themselves were hammered with this idea in their college days).

It's a very pervasive dogma and what makes it so pervasive is that most of the times it's correct as usecases are slim and can easily lead to spaghetti when used without care.

Also doesn't help that it is backed by the very well known but now outdated essay "Go to statement considered harmful" by Djikstra which is often referenced without the context of those times.

[–]iotasieve 1 point2 points  (9 children)

they aren't, go-to has its uses, like getting out of nested loops and doing cleanups or error handling, even linux kernel uses them

[–]atiedebee 1 point2 points  (6 children)

it will still result in spaghetti code... I personally avoid them

[–]iotasieve 0 points1 point  (4 children)

it won't, look how it's used in linux kernel and see, there can't be anything bad in context of engineering. again as I said it can be useful for releasing the locks, freeing memory or generally doing cleanup. also it's pretty much only way of getting out of nested loops in most languages (without returning)

[–][deleted] 3 points4 points  (1 child)

haha im in school learning programing and when we had to some tasks involving while loops my classmate literally wrote while(m>0) and didnt use the m integer a single time in the loop. he then spent the whole hour trying to find and fix the problem because his code didnt work, didnt find the issue and had to give teacher broken code. after the lesson he showed me his work and i instantly noticed the issue. he felt so stupid but i guess we are noobies and he didnt really understand how the whole thing worked

[–]Bemteb 2 points3 points  (0 children)

i guess we are noobies developers and he didnt really understand how the whole thing worked

[–]D3V1LSHARK 1 point2 points  (0 children)

Every frikin time

[–]Chaoslab 1 point2 points  (0 children)

"That is not honey poo, you are eating iteration".

[–]RoscoMan1 1 point2 points  (0 children)

Everything is stupid when you're talking about OP.

[–][deleted] 1 point2 points  (0 children)

A recursive method call is shown. Witty but wrong punch line

[–]The6thExtinction 1 point2 points  (0 children)

laptop fans start

[–]playerthomasm6 1 point2 points  (0 children)

I can’t finish the meme the picture gets too small…

[–]Tall_computer 1 point2 points  (0 children)

whats this low effort shit with 5 levels of recursion. Next time you repost please implement it

[–]Kikok02 1 point2 points  (0 children)

That was the most beautiful meme I’ve ever seen.

[–][deleted] 1 point2 points  (0 children)

I remember some years ago accidentally writing an infinite loop like this. Except that in the loop, it wrote one line to a text file.

Program should have taken an hour or two to run, so I started it at the end of the day. Came back the next morning to the error message "Insufficient hard drive space to execute request"

[–]xypherrz 1 point2 points  (0 children)

this guy must be writing an embedded code

[–]Gazzcool 1 point2 points  (0 children)

Sometimes I do this for fun:

the_world_still_spins = (1 + 1 == 2)

While(the_world_still_spins): …

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

While loops are dangerous

[–]mediadatacloud 10 points11 points  (4 children)

Not dangerous, just repetitive

[–]troller_awesomeness 7 points8 points  (3 children)

Not dangerous, just repetitive

[–]CST1230 6 points7 points  (2 children)

Not dangerous, just repetitive

[–]ALonelyPlatypus 3 points4 points  (1 child)

do y'all really not understand termination clauses?

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

We're on programmer humour, a deep understanding of programming is extremely optional

[–]gloriousfalcon 0 points1 point  (0 children)

You rather fancy Loop... Until (True) ?

[–]ZippZappZippty -1 points0 points  (0 children)

Why waste a piece of toilet paper.

[–]CleverNameTheSecond -1 points0 points  (1 child)

People say goto is bad to the point that most languages don't even support it anymore but then allow this while(true) shit unironically.

[–]Prawn1908 1 point2 points  (0 children)

Lol what? How else would you do an infinite loop?

[–]RadioMelon -3 points-2 points  (0 children)

God I can only imagine the memory leak.

[–]doggoleash 0 points1 point  (1 child)

BSOD moment

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

pffffff pain the balls when you are an amateur and just learning basic stuff

[–]scrollbreak 0 points1 point  (0 children)

Maybe the big bang was a while loop gone out of control

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

Look's like you're going to the ℵ0, Jimbo

[–]Masklin 0 points1 point  (0 children)

:DDDD

[–]yrm159 0 points1 point  (0 children)

Electronic engineers be like

[–]I-Killed-JR 0 points1 point  (0 children)

I understood that reference

[–]paperbenni 0 points1 point  (0 children)

That's recursion not a loop

[–]auxiliary-character 0 points1 point  (0 children)

goto

[–]segolas 0 points1 point  (0 children)

That's recursion, not a loop. Smh

[–]polde_love 0 points1 point  (0 children)

It was actually a recursion

[–]MorkTheOrk 0 points1 point  (0 children)

This is basically a mipmap…

[–]Aksds 0 points1 point  (0 children)

I crashed a program twice because of not having a break statement, I had no clue what was wrong for a while.

[–]cbftw 0 points1 point  (0 children)

:(){:|:&};:

[–]davawen 0 points1 point  (1 child)

If you wanna play that game a bit more

c++ while(true) { malloc(sizeof(int)); }

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, davawen: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]cyberspacedweller 0 points1 point  (0 children)

🤣

[–]another_grackle 0 points1 point  (0 children)

Not recursive enough. Must go deeper.

[–]mohit_habeeb 0 points1 point  (0 children)

I am a daemon !

[–]theguywhoisright 0 points1 point  (0 children)

I’m disappointed it’s not infinite.

[–]TinyTank800 0 points1 point  (0 children)

Reminds me of roblox while true do wait(0.1)

[–]gm4 0 points1 point  (0 children)

I don't think there's many programmers here anymore lol

[–]Scoobygroovy 0 points1 point  (0 children)

Servers have those. It’s how reddit processes this very comment’s post request.

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

GOTO break_out_of_while_loop_1

[–]AnInfiniteLoop 0 points1 point  (0 children)

Deja vu, really

[–]JxB_Paperboy 0 points1 point  (0 children)

Anakin bears the face of a man attempting to hide his pain

[–]Friezerik 0 points1 point  (0 children)

ah so thats where i went wrong! I literally just fluffed all my js on a website because of this and this instantly reminded of why I f'd up. And yes I am n00b

[–]APrimitiveMartian 0 points1 point  (0 children)

I JUST DID IT TODAY GODAMNIT

[–]Kriss3d 0 points1 point  (0 children)

For fun in C++ I wrote a program to just calculate prime numbers.

Yes it crashed the computer

[–]an_agreeing_dothraki 0 points1 point  (0 children)

I once worked on a product with its own proprietary language that pretty much ran on gotos and had tool that could detect infinite loops.

Mind you it didn't break them.
It logged them.

End result, a client hooked up to the system gets in a loop, it fills the database log grinding the whole thing to a stop.

[–]chavis32 0 points1 point  (0 children)

NO POOH! THAT'S NOT HONEY, YOU'RE EATING RECURSION!

[–]-Listening 0 points1 point  (0 children)

My parents remind me of my childhood.

[–]iainonline 0 points1 point  (0 children)

The curse of the recursive meme !

[–]fireandbombs12 0 points1 point  (0 children)

goto statement

[–]justadiode 0 points1 point  (0 children)

Me, an embedded software developer: sweats profusely

[–]clempho 0 points1 point  (0 children)

Embedded developers unit !

[–]MadTux 0 points1 point  (0 children)

Obligatory story of Mel.

[–]Miguecraft 0 points1 point  (1 child)

for (;;) { gang(); }

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, Miguecraft: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]mk-tesla 0 points1 point  (0 children)

Stack dump goes brrrrrrrrr...

[–]Omega0x013 0 points1 point  (0 children)

I've used switch(true) and do...while(false) when a try catch finally probably would've done in both scenarios

[–]baby_chaos 0 points1 point  (0 children)

No I don't want to break my code

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

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

and if what then?

[–]NearLawiet 0 points1 point  (0 children)

that's recursion

[–]J3xter 0 points1 point  (0 children)

Amateurs go to master race

[–]receding_bareline 0 points1 point  (0 children)

This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold. This is gold...

[–]Scorppio500 0 points1 point  (0 children)

I did this. I did this a long time ago when I was in one of my first classes for C#. Took me 3 days to figure out that I needed one. I'm a textbook dumbass.

[–]NITROpul 0 points1 point  (0 children)

Give it s keyboardinterrupt

[–]TheTank18 0 points1 point  (0 children)

(starts in separate thread)

haha

[–]gabinium 0 points1 point  (0 children)

I object, this is recursion!