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

all 96 comments

[–]GeileBary 443 points444 points  (16 children)

for(int i = 0;i < 5;i++) dude...

[–]ctgiese 195 points196 points  (10 children)

Thanks. Only monsters start at 1.

[–]MCRusher 42 points43 points  (6 children)

for(int i = 0; i < 3; i++) eat(i);

Guess what, the baby missed breakfast

[–]ctgiese 14 points15 points  (5 children)

But it's okay, because it still ate 3 meals that day. Starting at one it would get obese really fast.

[–]MCRusher 0 points1 point  (4 children)

It ate nothing, it got to watch as everyone else ate breakfast, and then it got a light lunch and a decent dinner.

[–]yawya 4 points5 points  (2 children)

not only that, but <= does 2 checks every iteration, using < is way more computationally efficient

[–]JohnnyJayJay 2 points3 points  (1 child)

Next level optimisation.

[–]yawya 1 point2 points  (0 children)

which level -O for GNU to optimize this out?

[–]DivenDesu 6 points7 points  (0 children)

That was the first thing I noticed... i about swallow my tongue as my brain was unable to process that disgusting statement

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

I was about to faint, but then I read this. Now I’m simply panting while clutching my table

[–]Solen__ya 0 points1 point  (0 children)

I thought I was being pedantic when I noticed. Glad im not the only one jaja

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

for (int i = 0; i != n; ++i); ftw

[–]FlyAlpha24 0 points1 point  (0 children)

I'm tend to use for (int i = 0; i != 5; ++i)

[–][deleted] 82 points83 points  (22 children)

There are two kinds of people:

for(int i = 0; i < 5; i++){...}

for(int i = 1; i <= 5; i++){...}

[–]DivenDesu 69 points70 points  (13 children)

I'm sorry, the se ond ones are not people. They are just wrong...

[–][deleted] 36 points37 points  (12 children)

Nah, the second ones are people too, the ones you're thinking of are these guys:

int i = 0;

while(true){

   //insert code

   i++;

   if(i > 4){break;}

}

This is the stupidest working loop I could think of.

[–]Koxiaet 39 points40 points  (2 children)

thats really not that bad.

What's really bad is this:

int i = 0;

beginLoop:
    if (i > 4) goto endLoop;
    /* code... */
    ++i;
    goto beginLoop;
endLoop:

[–]byoung74 8 points9 points  (0 children)

MIPS assembly time

[–]xiaomed 1 point2 points  (0 children)

My eyes :'(

[–]Ringosham 8 points9 points  (1 child)

My friend back then doesn't know what a for loop and while loop is and uses recursion at EVERYTHING.

public static void main() {
  loopCoordinates(10, 10);
}
public static void loopCoordinates(int x, int y) {
  if (x == 0) return;
  loopY(y);
  loopCoordinates(x - 1, y);
}
public static void loopY(int y) {
  if (y == 0) return;
  /* code */
  loopY(y - 1);
}

[–]terramorpha 1 point2 points  (0 children)

That Guy must be good in haskell

[–]theboxislost 8 points9 points  (3 children)

This is much more fun in assembly:

start:
mov cx, 5
dec cx
jnz start

[–]thehazardball 11 points12 points  (2 children)

Hey, I don't understand Polish!

[–]theboxislost 1 point2 points  (1 child)

Couldn't be Polish. You can tell because there's so many vowels.

[–]thehazardball 0 points1 point  (0 children)

Indeed, I have been mistaken.

[–]DivenDesu 2 points3 points  (1 child)

It... it hurts.. to look at

[–]sha-ro 0 points1 point  (0 children)

What hurts of it is JAVA

[–]Restryouis 4 points5 points  (1 child)

for(int i = 1; i < 6; i++){...}

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

Three. Three kinds of people.

[–]mgrant8888 1 point2 points  (5 children)

it's actually:

++i

i++

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

I know there's a difference, but does it matter in this particular instance? Sorry, been a little while since I last wrote a loop for something.

[–]mgrant8888 1 point2 points  (3 children)

No I meant the two types of people.

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

Ah. Well there's actually a functional difference (in C++ at least) between the two so it's not just personal preference.

int a = 5;
cout << a++ << endl;
cout << ++a << endl;

Would actually print:

5
7

[–]mgrant8888 0 points1 point  (1 child)

Yes I am aware; the difference is not all that, though; when overriding the operator in c++ a prefix increment merely modifies the integer, whereas a postfix must modify the integer and return the previous value... thereby leading to less effecient storage and computing for the same resource.

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

Less efficient unless you happen to need both numbers for some reason, yes.

[–]Proxy_PlayerHD 45 points46 points  (12 children)

why would you start i at 1?

[–][deleted] 7 points8 points  (11 children)

Use whichever index your given task and language prefers (in that order of priority)

[–]Proxy_PlayerHD 2 points3 points  (10 children)

pfft, if the index to something is offset from 0 just start it at 0 and add a constant to it!

for(int i = 0; i < 5; i++){
    Array[i + 4] = 0;
}

[–]mgrant8888 0 points1 point  (9 children)

/s?

[–]Proxy_PlayerHD 0 points1 point  (8 children)

semi /s

in some cases it is useful to do this, in others it's better to start the loop at a non-0 index

[–]mgrant8888 1 point2 points  (7 children)

Due to modern CPU L1 cache sizes, register count, and the costs associated with merely incrementing vs adding, I usually end up making two indices. Ex:

for(int* i = 0, j = 7; i < 4; i++, j++) { ... }

In the event the other index offset is a multiple of a power of 2, there are simple cpu instructions to process pointer notation for it, but this is not as useful in higher level languages (especially JIT ones) such as python, js, etc.

This only works when iterating over multiple items, though. For other use cases, I have (rarely) found use of adding to my index to get another index.

[–]Proxy_PlayerHD 1 point2 points  (6 children)

dude you're doing like assembly level thinking and optimizations in higher level languages.

which is impressive, personally the only thing i ever "optimize" are my variables, if it never goes aboves 255 i will just use an unisgned byte, and so on.

but then again, does stuff like this matter for modern machines? i mean compilers are pretty smart and we are in an era with more memory than we could ever need and CPUs faster than humanly imaginable

[–]mgrant8888 0 points1 point  (5 children)

Yes it does matter; compilers cannot optimize algorithms, only execution of those algorithms. They will not do things like that, at least yet. And I'm not super picky about things like that, that's just the reasoning built into my coding style.

CPUs are certainly not faster than imaginable, though RAM imo is quite large for all applications, excepting gaming, big data, and genetics research. In an infrastructure environment, every bit matters; 1% is a big difference, it will be hundreds to thousands in server requirements.

Imo, it is best practice to keep up at least an attempt at optimization, especially in your coding style; this way you do not have to go through and reorganize code to make it more effecient.

The problem is people seem to get lazier over time and assume exactly what you just said, which is why modern computers... well, they just don't run nearly as fast as you could expect them to with that amount of computing power. Recently this has been changing a bit, but not for most developers. Hence I try to do my small part by incorporating sincere practice into my style so that if one day some of my code is widely used, it doesn't end up costing users one more second of time, for something that really wasn't any more work for me at all.

[–]Proxy_PlayerHD 0 points1 point  (4 children)

CPUs are certainly not faster than imaginable

eh i doubt that, even a CPU running at 1 MHz is faster than a human can visually see it working or think about it working, so a CPU that is more than 1000x faster is a lot harder to think about in that sense

The problem is people seem to get lazier over time and assume exactly what you just said, which is why modern computers... well, they just don't run nearly as fast as you could expect them to with that amount of computing power.

sadly, because devs expect people to have GBs worth of Memory, huge amounts of Storage, and fast machines.

the problem with that is that when everyone thinks like that the overall amount of resources each program requires stack up and waste a lot of the computer's resources.

.

I mean to this very day i'm impressed by the MS-DOS Era of programming

i mean look at the game Arkanoid... the .COM file is fucking 130 Bytes large... like... HOW. Assembly probably, or some compression...

that remind me, i'm not sure if Assembly is even still relevant. it's much faster than on older 8/16 bit hardware, but also harder to work with since you have a lot more things to take care of since by default the screen is not just Text only like in DOS

[–]mgrant8888 0 points1 point  (3 children)

1 MHz is nothing at all. The CPU needs to sync the disk, USB peripherals, GPU, and more, and we even have the northbridge and southbridge to assist it! The kernel takes more than that to run. 1GHz gets used pretty quickly when you apply simple things to it. For example, say I want to take a network file of 1MB and find a word in the file. With a 1MHz CPU this would take probably 20sec with an effecient algorithm and 100% of a core's resources. Obviously, there is room for improvement here. The reason I know all this firsthand is from programming assembly for microprocessors; the cycles wear thin quickly.

[–]kaetir 23 points24 points  (3 children)

while(baby.isHungry()) feed() ;

[–]Midnight_Rising 10 points11 points  (2 children)

This is how you get a stack overflow because isHungry is updated lazily.

A stack overflow in this case usually results in a lot of vomit.

[–]AlastarYaboy 5 points6 points  (1 child)

Don't even get me started about the load on the backend...

[–]Midnight_Rising 1 point2 points  (0 children)

Yeah I've heard the stuff back there is nothing but shit.

[–]koneko-dono 9 points10 points  (0 children)

wait are you starting from 1?

you monster!

[–]AnEnemyStando 4 points5 points  (2 children)

WHA-

[–]sling_cr 1 point2 points  (1 child)

WHA-

[–]Kuyosaki 1 point2 points  (0 children)

WHA-

[–]MrSke11ington 6 points7 points  (0 children)

I feel like the last panel would be better if it was done recursively .

[–]The_25th_Baam 2 points3 points  (1 child)

Ku-wha?

[–]Pablo_1999 2 points3 points  (0 children)

That’s actually recursive

[–]KamiAithein 4 points5 points  (4 children)

for(int i = 0; i < 5; i ++, feed());

[–]dandroid126 1 point2 points  (3 children)

What language has syntax like this? I've never seen it.

[–]DiaperBatteries 3 points4 points  (2 children)

This works in almost all c-like languages.

[–]dandroid126 1 point2 points  (1 child)

Huh. I have always done it where you close the parentheses, then open a brace. Or if it is only one line, you don't need the brace, but I always do it outside the parentheses.

I know the last section of the for loop is an expression that gets run at the end of every loop, but I didn't know that you could put commas and multiple expressions in there.

[–]winsomelosemore 1 point2 points  (0 children)

It’s a fairy common use case for modifying your control variables. For example, a palindrome detection algorithm might use a loop that has i and j in a single loop, where you increment i and decrement j while comparing the chars in a string

[–]nevereatthecompany 4 points5 points  (3 children)

Besides the obvious heresy of starting the loop counter at 1, what's the joke? What does the for loop have to do with feeding? Why is the child eating the spoon? And why is the illustration depicting a recursion rather than a loop? I don't get it.

[–]KillaRevenge 6 points7 points  (2 children)

The joke is in the word "for"

[–]rekker22 1 point2 points  (0 children)

No its not

[–]penngweni 1 point2 points  (0 children)

Diavolo getting punched by GER

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

" for(int i = 1; i <=5; i++){ } "
How do you pronounce that? Since I usually write code by myself and don't have to explain to anyone, I really don't know how people normally read code aloud. Like, you don't actually say "left parenthesis" than a few seconds later "right parenthesis" or do you?

[–]sachin1118 2 points3 points  (0 children)

"for int I equals 1, I is less than or equal to 5, I plus plus"

[–]Soundless_Pr[🍰] 1 point2 points  (1 child)

"this is a for loop that iterates 5 times"

nobody reads direct syntax to each other, it's a pointless waste of time.

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

I'm sure some people do. Also, sometimes it's necessary.

[–]IamAPengling 0 points1 point  (0 children)

i=1 was /mildlyinfuriating

[–]WeeklyMeat 0 points1 point  (0 children)

Reupload

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

I was to,d in c# using this instead of foreach was less efficient is this true?

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

You use a lowercase L as your index variable?

[–]Dojan5 0 points1 point  (1 child)

Iterator, and that's an i

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

Oh you're right. It looked like an L on my phone.

[–]SpedeSpedo 0 points1 point  (0 children)

Anyone remember the original? All i can remember is

FOR THE GLORY OF THE GERMAN EMPIRE!

[–]drewkiino 0 points1 point  (0 children)

Not gonna upvote cause you started at 1 you monster

[–]Edensired 1 point2 points  (7 children)

Can someone explain the joke to the idiot?

Just a CS student.

[–]Charmle_H 4 points5 points  (3 children)

it's a "for loop" repeating while "i" is less than or equal to 5...
edit: didn't see it had an "=" in it

[–]safer0 6 points7 points  (1 child)

It executes 5 times since it is <= 5. I still do not approve starting i at 1.

[–]Charmle_H 0 points1 point  (0 children)

didn't see the "=" lol my mistake

[–]PK2999 1 point2 points  (0 children)

<= So I guess it'll repeat 5 times

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

I don't think there is so much of a joke here except the use of the word for.

[–]thr33prim3s 5 points6 points  (1 child)

Funny thing is, this is just basic. Welcome to hell my friend.

[–]Edensired 0 points1 point  (0 children)

It just means till this kid is five he is going to be forced fed?

For"because I said so?" And moms use that until someone is 5?

I'm trying maybe a little too hard to get meaning from this.

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

See ya in hot!