for Construct QuizJ8 Home « for Construct Quiz

Fundamentals Quiz 13

The quiz below tests your knowledge of the material learnt in Fundamentals - Lesson 14 -for construct.

Question 1 : Which loop statement was introduced in Java5 to iterate over collections?
- The <code>enhanced for</code> loop statement was introduced in Java5 to iterate over collections.
Question 2 : The condition component of a for loop is always tested againt the control variable for true after each iteration of the loop?
- The <i>condition</i> component of a <code>for</code> loop is always tested againt the control variable for <code>true</code> BEFORE each iteration of the loop.
Question 3 : Which statement will immediately exit a for loop?
- The <code>break</code> statement will immediately exit a <code>for</code> loop.
Question 4 : What will be output from this code snippet?

long [] anArray = {22}; for (int i : anArray) { System.out.println("Array element = " + i); }
- Doesn't compile. You can't fit a <code>long</code> into an <code>int</code>.
Question 5 : What will be output from this code snippet?

for (;;) {}
- Running <code>for (;;) {}</code> will create an infinite loop.
Question 6 : How could we force the next iteration of a for loop?
- The <code>continue</code> statement will force the next iteration of a <code>for</code> loop.
Question 7 : The initialization, condition, iteration and statement body components of a for Construct are all optional?
- The initialization, condition, iteration and statement body components of a <code>for</code> loop are all OPTIONAL.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz on Java is all about the while Construct.