Summary: Repetition Continued
This lesson summarizes the main concepts presented in this chapter.
We'll cover the following...
We'll cover the following...
- In a
forloop, the process step forms the body. The initialization, test, and update steps are included explicitly right after the reserved wordfor. - A
forloop has exactly the same logic as awhileloop. We typically use aforstatement for counted loops. - A
forstatement tests its condition immediately after any initialization occurs. Thus, the body of the loop might not execute at all. - We can omit either the initialization or the update step or both in a
forstatement, but we must retain the two semicolons. - When we declare two or more variables within a
forstatement, the variables must have the same data type. If they do not, we declare them before theforstatement. - The
dostatement executes its body, which includes the update step, before evaluating a Boolean expression to decide whether to continue the iteration. - We must write a semicolon at the end of a
dostatement. - Use a
dostatement when we know that the body of the loop will execute at least once.