5
Mitiko
6y

What do you prefer:

for(int i = 0; i <= maxValue; i++)

Or

for(int i = 0; i < maxValue + 1; i++)

Comments
  • 1
  • 4
    Definitely:

    for (int i = 0; i < maxValue; ++i)
  • 1
  • 1
    maxValue = maxValue +1
    for(int i = 0; i < maxValue; i++)
  • 3
    I prefer not writing for loops unless I really need to. If I need to, I'll use foreach or for ... in syntax, depending on the language.

    I make an effort to not write the classic for-loop.

    Use map, filter, reduce or any more abstract sequence helper function. It's far more readable and really describes your problem.

    Removing side effects is a nice bonus.
  • 1
    @Agred where is +1??
  • 0
    @sudo-rm-rf About going places, what do you mean with that ?
  • 0
    @FilipeRamalho Well, I cannot use the same variable again later on code. (I guess places means elsewhere in the code)

    @k0pernikus If this was js, I would consider. It is my fault for not specifying the language, though. C#

    @Agred I didn't see that one comming. But this way, I never really use index 0.
  • 0
    @Mitiko There are ways to achieve that if you only want it hard enough ;) (or use a library): https://stackoverflow.com/q/40075/...
Add Comment