Java Reference
In-Depth Information
while (num != -999)
//Line 8
{
//Line 9
sum = sum + num;
//Line 10; update sum
num = inFile.nextInt();
//Line 11; read the next number
}
//Line 12
System.out.println("Name: " + name
+ ", Votes: " + sum);
//Line 13
}
//Line 14
QUICK REVIEW
1 .
Java has
three
looping
(repetition)
structures: while , for ,
and
do ... while .
2 . The syntax of the while statement is:
while (logical expression)
statement
3 . In Java, while is a reserved word.
4 . In a while statement, the parentheses around the logical expression ,
the loop condition, are required; they mark the beginning and end of the
expression.
5 . The statement is called the body of the loop.
6 . The body of the while loop typically contains statement(s) that eventually
set the expression to false to terminate the loop.
7 . A counter-controlled while loop uses a counter to control the loop.
8 . In a counter-controlled while loop, you must initialize the counter before
the loop, and the body of the loop must contain a statement that changes
the value of the counter variable.
9 . A sentinel is a special value that marks the end of the input data. The
sentinel must be similar, yet different, from all the data items.
10 . A sentinel-controlled while loop uses a sentinel to control the while loop.
The while loop continues to execute until the sentinel is read.
11 . An EOF-controlled while loop continues to execute until the program
detects the end-of-file marker.
 
 
 
Search WWH ::




Custom Search