Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

For the first question, when I trace with i = 2, I do not know how to continue because list [3] when the length of the array is 3 [2,4,9] ?

asked in CSC212_Spring2019 by (1 point)

1 Answer

+2 votes

Notice the test in the for-loop is i < list.length - 1. If the array is [2, 4, 9], then list.length is 3 and list.length - 1 is 2. If i = 2, then test is 2 < 2 which is false so the loop body is not executed when i = 2.

answered by (1 point)
...