Exam 1z0-808 All QuestionsBrowse all questions from this exam
Question 164

Given the code fragment:

And given the requirements:

1. Process all the elements of the array in the reverse order of entry.

2. Process all the elements of the array in the order of entry.

3. Process alternating elements of the array in the order of entry.

Which two statements are true? (Choose two.)

    Correct Answer: B, D

    The enhanced for loop can only process the elements in the order of entry, thus fulfilling requirement 2. The standard for loop can handle all three requirements: it can process the elements in reverse order by adjusting the loop indices, in order by the normal loop progression, and alternately by modifying the step increment. Therefore, the statements that align with this are that requirements 1, 2, and 3 can be implemented using the standard for loop, and requirement 2 can be implemented using the enhanced for loop.

Discussion
akbiyikOptions: BD

The correct answer is BD

ann_9624Options: DE

finding true answer so D,E

iSnoverOptions: BD

Wrong, the correct answer is BD. and here's the explanation: * Standard For -> You can process all elements in reverse by putting the condition of " >=0", ">0" and putting in the increment "--var", "var--". You can put an alternating sequence by moving the increment, for example, if you want to jump from 2 to 2 places, in the for increment field you put "var = var +2" that will compile. About the correct sequence any for does. * Enchanced for -> You can only loop through the elements in the order of entry, you can't do it in reverse or alternately, as in enchanced for you access each element of the collection scalable (from smallest to largest in position).

iSnover

With these concepts, let's answer the questions: A -> Wrong, you cannot implement option 1 (reverse entry) and 3 (alternaty entry) in an enchanced for B -> Correct, you can use options 1,2,3 and a standard for C -> Wrong, you can implement option 2 (normal entry) and 3 (alternaty entry) in a Standard for D -> Correct, you can implement option 2 (normal entry) in an enchanced for And -> Incorrect, you can implement option 3 (alternaty entry) in a Standard for