Your browser has JavaScript turned off. This page is best viewed with Javascript enabled. Certain functions on this site will not work, and some style sheets will not load. Check your browser preferences to enable JavaScript.

Teach Yourself Java

Lesson 4 Quiz

1. What is a loop?
A new type of Applet
A segment of code to be run a specified amount of times
A segment of code to be run infinite times
A segment of code to be run once

2. What is essential in making sure that your loop is not infinite?
That there is a Boolean statement somewhere in your code
That your Boolean statement will at some point be false
That your Boolean statement will at some point be true
All of the above

3. Which is NOT a section of all types of loops?
Initialization
Loop Body
Test statement
The word "while"

4. In a ‘for’ loop, what section of the loop is not included in the parentheses after “for”?
Initialization
Loop Body
Test statement
Update

5. What would num be after the following code?

int num = 0;
for (int x = 0; x < 10; x++)
{
num +=2;
}
0
2
10
20

6. How many times does the following code loop?

int times = 4;
while (times < 24)
{
times = times * 2;
}
1
3
4
6