Loop Statements QuizJ8 Home « Loop Statements Quiz

The questions in this Java quiz are on the topics covered in the Java - Fundamentals section of the site. The table below lists the lesson used for each quiz, a description of the lesson content and the quiz number and questions associated with that lesson.

Fundamentals Quizzes Summary

Click on a lesson in the table to go to that lesson for a refresher on the topics for that quiz.

Click on a quiz in the table to go straight to the quiz for a particular lesson.

Fundamentals Lessons Description Quiz Info.
Lesson 2 - Code Structure & SyntaxFor this lesson we look at the code structure of a Java source file and look at some syntax.Quiz1
8 questions
Lesson 3 - Primitive VariablesThis lesson is about the primitive variable data types available in Java.Quiz2
8 questions
Lesson 4 - Method ScopeIn this lesson we look at Java method scope and what scope and its definition mean.Quiz3
8 questions
Lesson 5 - OperatorsThis lesson is the first of two about the symbols used in Java for mathematical and logical manipulation.Quiz4
6 questions
Lesson 6 - Bitwise OperatorsIn our second lesson on operators we look at the Java bitwise operators.Quiz5
6 questions
Lesson 7 - Conditional StatementsIn this lesson we look at the conditional statements available in Java.Quiz6
8 questions
Lesson 8 - Loop StatementsThis lesson is all about the loop statements available in Java.This quiz.
8 questions

Fundamentals Quiz 7

The quiz below tests your knowledge of the material learnt in Fundamentals - Lesson 8 - Loop Statements.

Question 1 : Which loop statement was introduced in Java to iterate over collections?
- The <em>enhanced for</em> loop statement was introduced in Java 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?
- False. It is tested BEFORE each iteration of the loop.
Question 3 : Which statement will immediately exit a loop?
- The <code>break</code> statement will immediately exit a 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 : Which loop statement is always guaranteed to execute at least once?
- The <em>do while</em> loop is always guaranteed to execute at least once.
Question 6 : What will be output from this code snippet?

boolean a = false; while (a = true) { System.out.println("In the loop""); a = false; }
- This code will compile fine, but when run creates an endless loop as each time we hit the <em>while</em> loop we assign <em>true</em> to the conditional expression.
Question 7 : How could we force the next iteration of a loop?
- The <code>continue</code> statement will force the next iteration of a loop.
Question 8 : The break statement exits all loops and continues at the next line?
- The <code>break</code> statement only exits the current loop.
To exit all loops you would need to use the <code>break</code> statement with a <code>label</code> statement that points to the outermost loop.
Quiz Progress Bar Please select an answer

What's Next?

The next quiz on Java is all about Arrays.