CSCI 1111 Chapter Notes - Chapter 4: Infinite Loop, For Loop, While Loop

54 views2 pages

Document Summary

Some behaviors should be repeated over and over, like a racecar driving around a track. A loop is a construct that repeatedly executes specific code as long as some condition is true. A while loop is a program construct that executes a list of sub-statements repeatedly as long as the loop"s expression evaluates true. If true, execution proceeds into the sub-statements inside the braces, known as the loop body. Each execution of the loop body is called an iteration while (expression) { // loop expression. // loop body: sub-statements that execute if the. // statements that execute after the expression evaluates to false. An infinite loop is a loop that will always execute. Commonly, a loop should iterate a specific number of times, such as 10 times. A loop variable counts the number of iterations of a loop. // iterating n times using loop variable i i = 1; while (i <= n) {

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