MIS 24053 Lecture Notes - Lecture 16: Code Segment, Infinite Loop, For Loop

9 views5 pages

Document Summary

Which loop to use? for loop for calculations that are repeated a fixed number of times controlled by a variable that is changed by an equal amount (usually 1) during each iteration while loop. The number of iterations depends on a condition which could be changed during execution. In some situations the code segment should not be executed at all. do-while loop. The code segment is always executed at least once. Otherwise, the situations when do-while loops are used are very similar to those when while loops are used. Known number of iterations before the loop stops (for). Test for a user-controlled condition before or after each iteration (while, do-while). Use the break command. break break is used when we want to terminate a loop before it ends in a normal way. When the break statement is executed, the loop statement terminates immediately. The execution continues with the statement following the loop statement.

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers
Class+
$30 USD/m
Billed monthly
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
7 Verified Answers

Related Documents