CS 18000 Lecture Notes - Lecture 5: Semicolon, Infinite Loop

99 views5 pages

Document Summary

Perform the same operation on different data. Accumulate information over a set of data. Repetition concept: repetition broken into two parts. Body of code that gets repeatedly executed. Condition (boolean) to determine when to stop: how to construct the body so that it does something different/useful each time it is run, the state of the computation must change with each iteration (otherwise nothing is done) Indefinite: loop until done ; no advance knowledge of how many iterations will be required: definite: loop a given number of times; used when the iterations are controlled by a counter or size or limit. If a boolean condition is true, repeat for loop. The while loop while (boolean-expression) { statements; : test boolean-expression first, if true, do statements in body, repeat from 1. Continue statement while (in. hasnext()) { word = in. next(); if (word. length() != 4) count=count+1; // is equivalent to . while (in. hasnext()) { word = in. next(); if (word. length() == 4) continue; else count=count+1;

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