APCS 6
what is the syntax of a while loop?
(probably should initialize some variables) while( boolean expression) { statements }
update action in a for statement
incrementing/decrementing the loop control variable
true/ false: ( ) are required
true
what is a nested loop?
a loop inside another loop
Boolean expression in a for statement
anything that evaluates true or false- testing the value of the loop control variable against a final value
what is difference between break statement and continue statement? (TEST Q)
break statements completely jump of the loop while a continue statement just skips the current iteration of the innermost loop.
for any loop to work correctly, 3 parts must be present (TEST Q)
counter initialization condition check counter update
true / false: you need a semicolon after the ( )
false
true or false: the indefinite loop and infinite loop are the same thing
false
true or false: the inner loops are DO NOT RESET every time the last statement is wrong and it restarts again at the first statement
false, it does RESET
true or false: it is not an infinite loop when there is NO COUNTER UPDATE
falso
the Java "for loop" is used to repeat a statement or a block of statements a _______________ number of times.
fixed
what is the syntax for the "for loop" statement?
for (initialization action; Boolean expression; update action) { statements; }
what are the 3 types of loops?
for loop, while loop, and for each loop.
what is the difference between a definite and indefinite loop? (TEST Q)
in a definite loop, the number of iterations is known, while in an indefinite loop the number of iterations is not known beforehand
initialization action in a for statement
is assigning a starting value to the loop control variable
each pass through a loop is called a/an...................
iteration
definite loops
number of iterations is known before we start the execution of the body of the loop- we know how many times it will repeat
indefinite loops
number of iterations is not known before
define continue statement
skips CURRENT ITERATION of innermost for or while loop
if the Boolean expression is false, then the loop is........
terminated
in a group of nested loops, which loop is executed the most number of times?
the innermost loop
what is the loop control variable?
the variable whose value determines whether another iteration is done
True or false: loop body is entirely skipped if boolean check is false the first time
true
true or false: each nested loop must have its own lcv
true
define break statement
used to jump out of the loop when specific condition occurs
when is a while statement used?
when there is a possibility that an entire loop body may skipped
when is "for loop" used?
when you know the exact # of iterations that occur