Professional Documents
Culture Documents
Introduction to Control
Statements
Fundamentals of Java
Objectives
2 Fundamentals of Java
Objectives (cont.)
3 Fundamentals of Java
Vocabulary
Control statements
Counter
Count-controlled loop
Entry-controlled loop
Flowchart
Infinite loop
4 Fundamentals of Java
Vocabulary (cont.)
Iteration
Off-by-one error
Overloading
Sentinel
Task-controlled loop
5 Fundamentals of Java
Additional Operators
6 Fundamentals of Java
Additional Operators (cont.)
Increment operator: ++
– Increase value of operand by 1
Decrement operator: --
– Decrease value of operand by 1
7 Fundamentals of Java
Standard Classes and Methods:
The Math Class
9 Fundamentals of Java
Standard Classes and Methods:
The Math Class (cont.)
10 Fundamentals of Java
Standard Classes and Methods:
The Random Class
11 Fundamentals of Java
The if and if-else Statements
Principal forms:
12 Fundamentals of Java
The if and if-else Statements
(cont.)
Additional forms:
13 Fundamentals of Java
The if and if-else Statements
(cont.)
Examples of if statements:
16 Fundamentals of Java
The if and if-else Statements
(cont.)
17 Fundamentals of Java
The if and if-else Statements
(cont.): Checking Input for Validity
19 Fundamentals of Java
The while Statement (cont.)
20 Fundamentals of Java
The while Statement (cont.)
Example:
Counter-controlled loop:
– cntr is the counter
– Loop repeats a determined number of times
21 Fundamentals of Java
The while Statement (cont.)
Counting backward:
23 Fundamentals of Java
The while Statement (cont.)
24 Fundamentals of Java
The while Statement (cont.)
25 Fundamentals of Java
The while Statement (cont.)
27 Fundamentals of Java
The for statement (cont.)
Example:
28 Fundamentals of Java
The for statement (cont.)
Count-controlled input:
29 Fundamentals of Java
The for statement (cont.)
30 Fundamentals of Java
The for statement (cont.)
32 Fundamentals of Java
Nested Control Statements and
the break Statement (cont.)
break statement: Prematurely end a loop
33 Fundamentals of Java
Nested Control Statements and
the break Statement (cont.)
34 Fundamentals of Java
Using Loops with Text Files
35 Fundamentals of Java
Using Loops with Text Files (cont.)
41 Fundamentals of Java