Part One
- We can use the
while
statement to evaluate an expression. - In order for the loop to continue, the statement in the brackets needs to evaluate to true.
- An infinite loop is a loop in which the
while
statement executes forever because the expression always evaluates to be true. - An iteration is the name for each time a loop executes.
Part Two
- It is a good idea to use a
for
statement to initialize, define, or change the value of loop variables after each iteration. - You would write a for-loop in code as the following:
init-statement;
while (condition-expression)
{
statement;
end expression;
}
}
- An off-by-one error occurs when the loop iterates one too many or one too few times.
Thanks!