Java OCA OCP Practice Question 1099

Question

How many of the loop types (while, do while, traditional for, and enhanced for) allow you to write code that creates an infinite loop?

  • A. One
  • B. Two
  • C. Three
  • D. Four


C.

Note

It is not possible to create an infinite loop using a for-each because it simply loops through an array or ArrayList.

The other types allow infinite loops, such as, for example, do { } while(true), for(;;) and while(true).

Option C is correct.

It is possible to create an infinite loop with for-each by creating your own custom Iterable.




PreviousNext

Related