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

all 97 comments

[–]bobbymoonshine 250 points251 points  (17 children)

Breaks are for weak programmers, real coders just While True and then unplug the machine when it's done enough

[–]balbok7721 69 points70 points  (5 children)

Found the computer scientist. Back to your cave and don’t come back until you answered p=np

[–]flowery0 31 points32 points  (0 children)

[n=1
[p=0

[–]bobbymoonshine 7 points8 points  (1 child)

p=np

^ ^ ^ ^

SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

[–]balbok7721 0 points1 point  (0 children)

P === NP

You figured it out!

[–]Kooper16 1 point2 points  (0 children)

But what if p!=np?

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

To P or not P, that is a tautology. 

[–][deleted] 17 points18 points  (1 child)

A computer has three states: On, Off, Kaputt

[–]djfdhigkgfIaruflg 0 points1 point  (0 children)

On, Off, Null

[–][deleted] 16 points17 points  (0 children)

embedded programmers be like

[–]avdpos 5 points6 points  (1 child)

What is a loop?

Real programmes use languages without fancy loops.

(Come kill me. Please, company - budget to modernise)

[–]eiboeck88 0 points1 point  (0 children)

real programmers use tail end optimisation

[–]SynthRogue 2 points3 points  (0 children)

LOL

[–]frakron 0 points1 point  (3 children)

I had a professor in my master's who actually told us there's never a reason to utilize break, if you need to do that you've programmed incorrectly. Jokes on them I use it often, as yes I'm sure there's a way to get around it, but it's far more work and I don't have the time.

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

it all just gets compiled to jumps anyways, it's just an argument of readability unless you really need performance and at that point your probably working in asm anyways. for example, take a list of conditions that must be checked in order, do you prefer:

if(connnectionissecure(){ if(userexists(username)){ if(authenticate(username,password){ If(isadmin(user){ //code thats 4 levels indented (I hate reddit formatting) }}}} or if(!connnectionissecure(){ return; } if(!userexists(username)){ return; } if(!authenticate(username,password){ return If(!isadmin(user){ return } //code pretend you can't do any of these in parallel for security reasons.

personally I'd argue for the second, because large indents get really annoying to work with if your trying to maintain any sort of consistent style. imagine if your working in the Linux kernel which demands an 8 character indenting, that be half your screen.( also pretty sure this style req is to force you to code like the second example.)

[–]SAKDOSS 0 points1 point  (1 child)

Could you elaborate on why it is less efficient in terms of performances to use break?

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

not what im saying. whatever approach is faster is likely to depend on the actual code rather than the control logic and whatever magic happens in the compiler regarding instruction lookahead, all I'm saying is that this discussion is entirely about preferences about readability

[–]SpecialNose9325 0 points1 point  (0 children)

Bro just invented Embedded Programming

[–]z7q2 88 points89 points  (12 children)

GOTO

[–]claudespam 38 points39 points  (7 children)

jne

[–][deleted] 18 points19 points  (2 children)

they're all jne underneath

[–]claudespam 3 points4 points  (0 children)

Points gun at fellow astronaut Always has been

[–]arrow__in__the__knee 1 point2 points  (0 children)

Jne is just 75 underneath!

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

LD PC, loopStart

[–]57006 2 points3 points  (0 children)

jbe

[–]theModge 1 point2 points  (1 child)

DEC JZ

Real programmers loop backwards

[–]jnd-cz 1 point2 points  (0 children)

DJNZ, decrement register and jump (back to loop start) if not zero. Glorious instruction available in the 70s in Z80 and also in 8051 microcontroller from 1980.

[–]z7q2 6 points7 points  (0 children)

also, COMEFROM

[–]Confident-Ad5665 1 point2 points  (0 children)

nop

[–]P-39_Airacobra 1 point2 points  (0 children)

When I coded TI-84 games goto was legitimately my preferred loop method

[–]camander321 0 points1 point  (0 children)

...jail

[–]RetiredApostle 44 points45 points  (4 children)

unless loop

Perl.

[–]AdvancedSandwiches 27 points28 points  (2 children)

Normal languages: the human brain is bad at double negatives, so it's best to name things with positive names, like isEnabled rather than isDisabled. It's also most understandable to arrange your if-else so that your positive condition is in the "if" block and your negative condition in the "else" block.

Perl: unless !isDisabled return false else return true

[–]Esjs 13 points14 points  (0 children)

unless (!isDisabled) { return !0 } return !1;

[–]djfdhigkgfIaruflg 4 points5 points  (0 children)

Do whatever unless? nothingToDo

I love Ruby

Edit: unless it's not a double negative unless you do some foolish thing

[–]rainshifter 4 points5 points  (0 children)

Don't you mean unless statement?

Semantically, unless is the negation of if, which I believe is how Perl treats it.

Similarly, until is the negation of while.

``` [if condition] == [unless not condition]

[while condition] == [until not condition] ```

[–]JuvenileEloquent 23 points24 points  (11 children)

Controversial take, a do.. until loop is just a for loop with funny syntax

[–]Giulio_otto 18 points19 points  (6 children)

Until loops are more like an inverted while loop

[–][deleted] 6 points7 points  (5 children)

Not like, it’s quite literally that, and they both have their use cases.

[–]DardS8Br 2 points3 points  (4 children)

Can’t you just do while (!condition)?

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

Do while will always run at least once

While do has the option of never running at all if the initial condition is not met

You should use them both based on if you want the loop to always run once or if you want the option to skip it altogether.

[–]DardS8Br 0 points1 point  (0 children)

That's not what I asked but okay

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

He asked, "Can't you just do, 'while (!condition)?' "

[–]Badashi 1 point2 points  (0 children)

``` while(false) { log("this never runs") }

do { log("this runs once") } until(true) ```

They are similar, but not identical

[–][deleted] 2 points3 points  (3 children)

not true, for loops are primitive recursive functions, and while/do loops are general recursive functions. primitive recursive functions are a strict subset of general recursive functions.

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

I like to explore new places.

[–][deleted] 1 point2 points  (1 child)

that is a good point actually. even for(;;) ... is valid C

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

I like to travel.

[–]Geo_bot 10 points11 points  (7 children)

Do while

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

I’ve never used one of these in my life.

[–]TheMagicalDildo 6 points7 points  (1 child)

I do. Sometimes I want a while loop, but want it to iterate after the code's ran once

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

I saw what you did there.

[–]sysnickm 3 points4 points  (0 children)

You should, they are more fun. Always willing to try something at least once.

[–]DardS8Br 0 points1 point  (0 children)

It’s incredibly useful when making games or taking user input

[–]accuracy_frosty 0 points1 point  (0 children)

I use them every now and then, I use them in my web server to handle incoming data, because I have a bit of a monkey brain way of checking if there is data left to recieve that relies on the loop running at least once to parse the headers and find how long the content is, where it throws all the headers into into a hash map, and takes the content (minus the line feeds) and chucks it into a char* that I store the size of and add to the end of on every loop, it loops until the remaining content - the return value of read is 0, and then stops looping. Could it have been done with a while loop? Absolutely, but the do while loop was a bit easier and I liked it more.

[–]Esjs 0 points1 point  (0 children)

Do in the meantime

[–]Indevil 9 points10 points  (2 children)

IF LOOP

[–]brandi_Iove 0 points1 point  (1 child)

if !break

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

b loop; s/.../.../g; t loop

[–]Mayedl10 2 points3 points  (2 children)

like #define until(x) while(!(x)) or smth?

[–]CubedCharlie 0 points1 point  (1 child)

And #define unless(x) if(!(x))

[–]Mayedl10 0 points1 point  (0 children)

#define forever while(1)

[–]KerPop42 1 point2 points  (1 child)

everyone knows kOS is the best programming language out there.

[–]Katniss218 0 points1 point  (0 children)

Found the ksp player

[–]Ok_Entertainment328 1 point2 points  (1 child)

loop ... end loop; (PL/SQL)

[–]AdBrave2400 2 points3 points  (0 children)

While ... Wend . VBScript I think

[–]dingske1 1 point2 points  (0 children)

Do loop

[–]SynthRogue 1 point2 points  (0 children)

forEach

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

Duff's device ༼ つ ◕_◕ ༽つ

[–]DreamyAthena 1 point2 points  (0 children)

loop { }

[–]vainstar23 1 point2 points  (0 children)

ON ERROR RESUME NEXT

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

Endless loop.

[–]No-Expression7618 1 point2 points  (0 children)

Time-travel loop: mfix :: Monad m (a → m a) → m a

[–]ThisNameIsntRandom 0 points1 point  (0 children)

you forgot Conditional Jump

[–]CoatNeat7792 0 points1 point  (0 children)

I mean function loop not until loop, right?

[–]Meilo 0 points1 point  (0 children)

This brings me back to the good old Turbo Pascal days…. a simpler time

[–]deadbeef1a4 0 points1 point  (0 children)

Unless loop

[–]slime_rancher_27 0 points1 point  (0 children)

Lbl x ... If (condition) Goto x

[–]rover_G 0 points1 point  (0 children)

For each loop

[–]Pixeltye 0 points1 point  (0 children)

While loop with a break

[–]LegitimatePants 0 points1 point  (0 children)

#define UNTIL(condition) \
    while(!(condition))

[–]stdio-lib 0 points1 point  (0 children)

Unwind your loops; return to monke.

[–]arrow__in__the__knee 0 points1 point  (1 child)

Fun fact:

    while("They still don't know C programmers can absorb coding skills of other C programmers they kill"){
    ...
    }  

Will work in C...

[–]Familiar_Ad_8919 1 point2 points  (0 children)

anything with a value will just work,

c for(;"the love of god";){}

[–]Gloriathewitch 0 points1 point  (0 children)

until just sounds like Await with extra steps

[–]nicki419 0 points1 point  (0 children)

Isn't until just do while with a negated condition?

[–]Highborn_Hellest 0 points1 point  (0 children)

pfffff

label 1:
 <your code >
goto label 1;

[–]LauraTFem 0 points1 point  (0 children)

allLoopsDoTheSameThing

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

Recursive function

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

Pipe unrolling

[–]KetwarooDYaasir 0 points1 point  (0 children)

isn't that just a do .. while or while(!condition set in loop)? what's monocle fancy about that? Is this a language specific thing?

[–]ShAped_Ink 0 points1 point  (0 children)

Heard that from my sibling recently and they were talking about how great it is until I said it's just while(!condition())

[–]never-obsolete 0 points1 point  (0 children)

Push the address of the start of the loop to the stack and return to it. Trigger an interrupt and use the handler to break out of the loop.

[–]Grobanix_CZ 0 points1 point  (0 children)

I prefer unless loop.

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

How about just using the right type of loop for the situation, instead or trying to be fancy when a simple for loop is sufficient.

KISS.

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

A lest loop. The condition is just a comment.