This question belongs to Swift Programming Language , specifically the objectives covering arrays , loops , and range operators . The array has 6 elements, so menuItems.count is 6. The loop uses the half-open range operator:
for index in 1.. < (menuItems.count - 1)
That becomes:
for index in 1.. < 5
In Swift, the half-open range operator a.. < b includes the lower bound but does not include the upper bound. So this loop runs with index values 1, 2, 3, 4, not 0 and not 5.
Array subscripting uses those indexes to print:
menuItems[1] → " Burger "
menuItems[2] → " Chicken "
menuItems[3] → " Pasta "
menuItems[4] → " Salad "
That means " Pizza " at index 0 is skipped, and " Steak " at index 5 is also skipped. Swift arrays use zero-based indexing, and count returns the number of elements in the array.
Therefore, the program prints only " Burger " , " Chicken " , " Pasta " , and " Salad " , so the correct answer is A .
Submit