+ 5

Is their any difference in iterating a for loop from top to bottom and bottom to top in time? if so what is the reason?

The main Difference.

14th Jul 2017, 2:40 PM
Bharath kumar
Bharath kumar - avatar
3 Antworten
+ 9
I mean that if you want to print "1" 100 times using a for loop by iterating from 1 to 100 and 100 to 1, Will there be any difference in time taken for Execution.?
15th Jul 2017, 12:41 AM
Bharath kumar
Bharath kumar - avatar
+ 2
Likely not. It's the same thing backwards. However, using ++i instead of i++ can make a difference in execution time (We're talking nanoseconds). for(int i = 0; i < 100; ++i){} i++ must first keep track of the variable: int temp = i; Do the operation. i = blah; Then increment it. i = i + 1; Meanwhile ++i just increments. i = i + 1. So, you can generally expect ++i to be a faster operation.
15th Jul 2017, 1:12 AM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Uh.. top to bottom and bottom to top can mean many things.
14th Jul 2017, 3:47 PM
Rrestoring faith
Rrestoring faith - avatar