Ask Question

Assuming arrayName is the name of an array and identifier is a name of a variable that has the same data type as the array elements, which of the follow is the correct syntax for the range-based for loop?

a) for (dataType identifier : arrayName) statements

b) for (dataType : arrayName) statements

c) for (identifier : arrayName) statements

d) for (arrayName : dataType identifier) statements

+2
Answers (1)
  1. 9 October, 09:02
    0
    The answer is "Option a"

    Explanation:

    Range-based for loop performs a sequence for a loop. It's more accessible as the conventional loop, for example, all components in the array, running more than a range of possibilities. In the given question "option a" is correct because it follows the correct syntax and other choices were wrong, which can be described as follows:

    In option b, It's not correct, because in this code the range declaration is wrong. In option c, It is wrong, because in this code the datatype is missing. In option d, It is illegal syntax, that's why it is wrong.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Assuming arrayName is the name of an array and identifier is a name of a variable that has the same data type as the array elements, which ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers