I'm writing simple JS code which should print exponents of number 3 with limit of 1000. I decided to use while loop
, and I am curios if I use if
statement inside my while
loop will it slow down the execution of the loop?
var print=0,i=0;
while(check<10000)
{
print=Math.pow(3,i);
if(print<1000)
console.log(print);
else
break;
i++;
}
Of course, I don't mean in this particular part of code, because this is very simple. Or maybe I should use following code:
var print=0,i=0,check=0;
while(check<10000)
{
print=Math.pow(3,i);
console.log(print);
i++;
check=Math.pow(3,i);
}
In this case 3 variables are in use. Which way is better/faster? Thanks in advance.