COSC 236 Lecture Notes - Lecture 5: For Loop

58 views2 pages

Document Summary

Loops 2 lecture: a pre-test loop, allows the programmer to initialize a control variable, test a condition, and modify the control variable all in one line of code, combines initialization, condition, and statement all in one sentence, form: Ex. --> for (int num = 1; num <= 10; num++) { statements;} { statements;: executes code update checks condition, *good to use when you know how many times you want the loop to run. Multiple initializations and updates: the 3 elements of this are optional, the only mandatory parts are the ;; Sentinel values: sometimes the end point of input data is not known, this can be used to notify the program to stop acquiring input. If a loop is nested, the inner loop will execute all of its iterations for each time the outer loop executes once. Break statements: can be used to abnormally terminate a loop, exists entire loop, considered to be bad form.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents