Why Repetition is Needed: Show
Types of Repetition Structures Two types of repetition structures: pretest and posttest loops
while LoopUsing while Loop:
for LoopUsing for Loop:
do...while LoopUsing do...while Loop:
break and continue Statements (alter flow of control)Using break Statements:
FYI... In a while loop, when the continue statement is executed, if the update statement appears after the continue statement, the update statement is not executed. In a for loop, the update statement always executes. In general, avoid using break and continue to escape loop and branch code (one exception would be in switch statements). Instead consider adding/changing the exit conditions of the control statement. Likewise, even though permitted (due to backward-compatibility) refrain from using goto statements. With that said, also consider how sometimes generalized rules may be reconsidered under specific circumstances. |