-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
  • 16,053
  • 9
  • 49
  • 91
Varun Bajpai
  • 545
  • 5
  • 20

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,318
  • 1
  • 14
  • 24