-
Consider the following code snippet.
function printArr(n)
{
var len = n.length, p = 2;
if (len == 2)
console.log("Nothing is in Array");
else
{
do
{
console.log(n[p]);
} while (++p < len);
}
}
What does the above code result?
-
- Prints the numbers in the array in the reverse order
- Prints the numbers in the array in order
- Prints “Nothing is in Array”
- Prints 2 to the length of the array
- None of these
Correct Option: B
The do/while statement creates a loop that executes a block of code once, before checking if the condition is true, then it will repeat the loop as long as the condition is true. Hence the iterator traverse through the array and print them in normal order.