Discussion :: Javascript - CS
-
Which is a more efficient code snippet ?
Code 1 :for(var num=10;num>=1;num--)
{
document.writeln(num);
}
Code 2 :var num=10;
while(num>=1)
{
document.writeln(num);
num++;
}
Answer : Option A
Explanation :
A for loop is always more efficient because it encapsules two individual statements(initialization and expression) within the braces.
Be The First To Comment