-3

Just having a question that any of the following loop is better or both are same

option 1

for(i=0; i<=3; i++)
{
    //Do something
}

option 2

for(i=0; i<4; i++)
{
    //Do something
}
Marius Bancila
  • 15,632
  • 8
  • 47
  • 86
Varun Bajpai
  • 535
  • 5
  • 18

1 Answers1

1

Those two loops are identical in execution. The second part of the for expression is the comparison to be used to determine continuation of the loop; since you are starting from zero and incrementing by one, these two expressions will always yield the same results.

Boluc Papuccuoglu
  • 2,273
  • 1
  • 13
  • 24