Professional Documents
Culture Documents
Lecture #7
Spring 2017
• Branching Structure
• Selection Criteria
• Relational and Logical Operators
• The if-else statement
• Nested if statement
• The switch statement
• Looping Structure
• Basic loop structures
• while loops and for loops
• Nested Loops
• do while loops
Case study: [General Math]: Solving Quadratic Equations
[Physics]: Flight of a Ball
Reading assignment
– Chapter 4 of the textbook
– Chapter 5 of the textbook
2
Selection Criteria ASTU
3
Selection Criteria ASTU
4
Relational Operators ASTU
5
Relational Operators ASTU
7
Logical Operators ASTU
8
Operator Precedence ASTU
9
A Numerical Accuracy Problem ASTU
10
The if-else Statement ASTU
11
The if-else Statement ASTU
12
The if-else Statement ASTU
13
Compound Statements ASTU
14
Compound Statements ASTU
15
One-Way Selection ASTU
16
Common Problems with if-else ASTU
17
Nested if Statements ASTU
18
Nested if Statements ASTU
19
The if-else Chain ASTU
20
The if-else Chain ASTU
21
The if-else Chain ASTU
22
The switch Statement ASTU
23
The switch Statement ASTU
24
Case Study: Solving Quadratic Equations ASTU
25
Step 1: Analyze the Problem ASTU
26
Step 2: Develop a Solution ASTU
27
Step 2: Develop a Solution(Refining) ASTU
29
Step 3: Code the Solution ASTU
30
Step 4: Test and Correct the Program ASTU
31
Basic Loop Structures ASTU
32
Basic Loop Structures ASTU
33
Pretest and Posttest Loops ASTU
• Pretest loop:
– Condition is tested first;
– if false,
• statements in the loop
body are never executed
• while and for loops
are pretest loops
34
Pretest and Posttest Loops ASTU
• Posttest loop:
– Condition is tested after
the loop body
– statements are executed;
• loop body always
executes at least once
• do while is a posttest loop
35
Fixed-Count versus Variable Condition Loops ASTU
36
while loops ASTU
37
while loop example ASTU
38
while loop example ASTU
39
break statement ASTU
40
break statement example ASTU
41
continue statement ASTU
42
continue statement example ASTU
43
for loops ASTU
44
for loops ASTU
45
for loop example ASTU
46
For Loop Flow of Control ASTU
47
Nested Loops ASTU
48
Nested Loops Diagram ASTU
49
Nested Loops Example ASTU
50
do while loop ASTU
51
do while loop flowchart ASTU
52
do while loop flow of control ASTU
53
common use of do while loop ASTU
54
Case Study: Flight of a ball ASTU
55
Case Study: Flight of a ball ASTU
57
Case Study: Flight of a ball ASTU
58
Case Study: Flight of a ball ASTU
59