Java OCA OCP Practice Question 461

Question

Which of the following are legal loop definitions? (Choose all that apply.)

  • A. while (int a = 0) { /* whatever */ }
  • B. while (int a == 0) { /* whatever */ }
  • C. do { /* whatever */ } while (int a = 0)
  • D. do { /* whatever */ } while (int a == 0)
  • E. for (int a==0; a<100; a++) { /* whatever */ }
  • F. None of them are legal.


F.

Note

A through D are all illegal because only for loops allow loop variables to be declared in the loop control code.

E is illegal because the variable must be initialized with =, not ==.




PreviousNext

Related