Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@SukMikeHok
superman = 0;
pizza:
do_shit(superman);
if (++superman == motorbike) goto gayporn;
goto pizza;
gayporn: -
@Taqriaqsuk Not neccessarily - let's say I need to output a table in PHP in an application designed for end users.
I wouldn't want the row numbers to start with 0 so as not to confuse the users (let's face it, the majority of people starts to count at 1). If nothing else requires i to start at 0, I'd of course start it at 1.
Though I always prefer using a while or foreach loop if it improves readability. -
@ilPinguino I still prefer idiomatic loops like each_with_index, but I get your point
-
Oh, and since noone added it...
MOV 1, ECX
MOV 5, EDX
loop:
ADD 1, ECX
CMP ECX, EDX
JLE loop
From the top of my mind, might be wrong. -
@Gregozor2121 should be i>0 and not i<0. A for loop runs while the condition is fulfilled, not until the condition is fulfilled.
For negative n, this is not an issue, but then it relies on signed integer overflow for termination, which is undefined behaviour. -
@D3add3d me too. Also, it's like a watermark for me because no one else in the company does that 😄
-
@Lensflare interesting 🤔
it was like the 4th thing they taught us at uni... do your colleagues have uni degrees? -
@D3add3d Some of them have uni degrees. I have uni degree myself but I wasn't told about the memory and performance implications of preincrement vs. postincrement there. I learned that from the internet by myself. I also do remember that the difference is miniscule at best. 😁
-
@D3add3d not for basic data types, i.e. not at all in C. In C++, only for object types / iterators.
-
And even in C++ iterators, it doesn't make a difference in the last statement of "for" because it's enclosed in sequence points. The compiler will generate the same machine code with optimisation.
Incrementing iterators within a loop body is where it can make a difference.
Two kind of programmers
joke/meme