-
Which is a more efficient code snippet?
Code 1 :for(var n=10;n>=1;n--)
{
document.writeln(n);
}
Code 2 :var n=10;
while(n>=1)
{
document.writeln(n);
n++;
}
-
- Code 2
- Code 1
- Cannot Compare
- Both Code 1 and Code 2
- None of these
Correct Option: B
Code 1 would be more efficient. Infact second code will go into runtime error as the value of num will never reach less than or equal to one.