CS 0007 Lecture 6: Loops

26 views1 pages
10 Oct 2017
School
Course
Loop Controls
Controls that allow for a program to have repeated paths of execution
Types of loops
Iteration: cycle of something
While (boolean exp) { }
execute if true, then reevaluate
do { …………………} while (exp);
repeat if true
for ( ) { …….. ]
lets you control a fixed number of iterations
DoWhile Loop
int x = 0;
do
{
System.out.println(x);
- - x;
} while (x>0);
This repeats only when the expression is true
This is better for asking the user
While Loop
int x =0;
while (x> 0 )
{
System.out.println(x);
- - x;
}
This repeats until the expression is false
find more resources at oneclass.com
find more resources at oneclass.com
Unlock document

This preview shows half of the first page of the document.
Unlock all 1 pages and 3 million more documents.

Already have an account? Log in

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