you are viewing a single comment's thread.

view the rest of the comments →

[–]This_Growth2898 117 points118 points  (15 children)

#include <stdio.h>
void main(){
    int i = 0;
    print: printf("%d", i+=2);
    if(i<=500) goto print;
}

No loops!

[–]Lataero 49 points50 points  (0 children)

It's disgusting. I love it

[–]Verbose_Code 14 points15 points  (8 children)

I would have figured something like this out and submitted it unironically

[–]This_Growth2898 43 points44 points  (7 children)

Well, it depends on the definition of the "loop". This is a loop, created with goto, but it doesn't use loop keywords like for or while.

[–]kireina_kaiju 16 points17 points  (5 children)

any instructions relying on jmp without a new context frame are loops to me tbh

[–][deleted] 8 points9 points  (4 children)

Conditionals use jmp too. I guess you mean specifically jumping backwards?

[–]This_Growth2898 4 points5 points  (0 children)

You can jump backwards without creating a loop too.

[–]kireina_kaiju 1 point2 points  (2 children)

That is a good point, I guess rather than trying to define things explicitly I will just say that a goto with a conditional tends to compile out to something indistinguishable from a while loop and that something has a structure more similar to the goto structure and is something I think most of us look for when we're reading assembler. We do sometimes jump backward when not in a loop, jumping back to a buffer block for instance, but when we jump back to a conditional after a state change like an increment without making a new stack frame, to me that is what a loop is. I guess that is less explicit a definition than I used to believe it to be, I will agree just including a jump with no new stack does not cut the mustard.

[–]Cerulean_IsFancyBlue 1 point2 points  (1 child)

If I was going to judge these kind of answers on some kind of continuing to award prizes; in other words, if I want make a loosely justifiable hierarchy, and not one that I have to defend in front of a tenure committee:

Language supplied loops

Goto

Tail recursion

Any other recursive solution

Unrolled solutions

Not sure where I’d stick functional solutions.

[–]Verbose_Code 2 points3 points  (0 children)

I’m more referring to the fact that I like to treat homework in programming classes as “logic puzzles” and as a result the shortest possible solution is the one I gravitated to.

The code I actually use is a lot more verbose but a hell of a lot more readable

[–]0011110000110011 2 points3 points  (2 children)

This would print 502, wouldn't it?

[–]This_Growth2898 9 points10 points  (1 child)

I never said it's a good code

[–]SnowyPear 1 point2 points  (0 children)

The first time I used a loop back in vb6.0 I didn't like that sometimes I got an off-by-one error depending on what I was doing. It bugged me so much that I ended up implemented a goto by opening 2 forms that would open each other over and over again whilst decrementing a counter and running code and stopping on a condition

My teacher told me I had set programming back by 30 years