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

Respuesta :

Answer:

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.