2.
list = [10, 5, 15);
for(var i = 0; ; i++) {
console.log(list[i]);
Which of the following will NOT result in an error if placed where the program reads and the program is run?
OOOO
A. 1 < list[list.length)
B i < list.length
C. 1 < list[0]
D. 1 < list[1]

Respuesta :

Answer:

B. i < list.length

Explanation:

This question is terribly worded, but I assume the meaning is which answer will not result in an error if it's used in the while condition of the for loop.  The correct answer is b.  i < list.length is telling the loop to continue as long as the variable i is less than the length of the array list.

Answers C and D could potentially be valid under certain circumstances, but very unusual.  Answer A will give an error as list[list.length] will give an undefined value (assuming this is indeed javascript and not some other languge).

The program illustrates the use of loops

The correct statement is (b)  i < list.length

The program is given as:

list = [10, 5, 15];

for(var i = 0; ; i++) {

console.log(list[i]);}

The for loop has a missing statement, which is meant to end the iteration.

From the list of given options, option B will end the iteration, and the program will run without error.

So, the program becomes

list = [10, 5, 15];

for(var i = 0; i < list.length ; i++) {

console.log(list[i]);}

The above program will print every element of the list

Read more about loops at:

https://brainly.com/question/4261753

ACCESS MORE
EDU ACCESS
Universidad de Mexico