ptg7068951
106 HOUR 8: Repeating an Action with Loops
Quiz
- What must be used to separate each section of a forstatement?
A. Commas
B. Semicolons
C. Off-duty police officers - Which statement causes a program to go back to the statement that
began a loop and then keep going from there?
A. continue
B. next
C. skip - Which loop statement in Java always runs at least once?
A. for
B. while
C. do-while
Answers
- B.Commas are used to separate things within a section,but semi-
colons separate sections. - A.Thebreakstatement ends a loop entirely,and continueskips to the
next go-round of the loop. - C.Thedo-whileconditional isn’t evaluated until after the first pass
through the loop.
Activities
If your head isn’t going in circles from all this looping,review the topics of
this hour with the following activities:
. Modify the Benchmarkprogram to test the execution of simple mathe-
matical calculation such as multiplication or division.
. Write a short program using loops that finds the first 400 numbers that
are multiples of 13.
To s e e J av a p r o g r a m s t h a t i m p l e m e n t t h e s e a c t i v i t i e s ,visit the book’s website
at http://www.java24hours.com.