CS 18000 Lecture Notes - Lecture 4: While Loop, For Loop, Semicolon

44 views2 pages

Document Summary

Indefinite: loop until done, there is no advance knowledge of how many iterations required. Definite: loop a given number of times, iterations are controlled by a counter or size or limit. While loop: checks a boolean condition, if true, executes a block of statements and repeats it. Example: while (sc. hasnextint(s)) { a = next. int(); number = number + a. } basically (cid:449)hat(cid:859)s happening here is as long as the scanner as an integer input, it will add it to the variable we declared as number. Do-while loop: first executes a block of statements, if a boolean is true, it repeats them. For loop: executes a block of statements a specific amount of times. T(cid:396)i(cid:374)g (cid:396)e(cid:448)e(cid:396)se (cid:894)s(cid:895) exa(cid:373)ple: s. e(cid:395)uals(cid:894)(cid:396)e(cid:448)e(cid:396)se(cid:894)s(cid:895)(cid:895) (cid:449)e a(cid:396)e (cid:272)o(cid:373)pa(cid:396)i(cid:374)g st(cid:396)i(cid:374)g s (cid:449)ith its (cid:396)e(cid:448)e(cid:396)se to test if it(cid:859)s a palindrome. Compound assignment: use these shortcuts to save keystrokes. X = x+ y; -> x += y; A = a b; -> a -= b;

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