1 x = 3 true We continue by drawing the flowchart. It will be our map as we walk the code line by line."> 1 x = 3 true We continue by drawing the flowchart. It will be our map as we walk the code line by line.">
Download presentation
Presentation is loading. Please wait.
Published byJames Adams Modified over 9 years ago
1
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); Let’s think about this code. What does it do, how does it work?
2
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x = 3 We visualize the instructions one by one. First x gets created and is assigned a value.
3
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 true We continue by drawing the flowchart. It will be our map as we walk the code line by line.
4
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 2 true
5
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 2 { true
6
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 { true
7
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “one” { true
8
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “one” { } true
9
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “one” { } true
10
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “one” { } true
11
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “one” { } true
12
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” { } true
13
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” { } true
14
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” { } true
15
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” { } true
16
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” “four” { } true
17
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” “four” { } true
18
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” “four” { } The end. true
19
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); x > 1 x = 3 x > 3 x > 2 “three” “one” “four” { } The end. Nothing gets printed. true
20
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); Old problem
21
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem
22
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); Old problem
23
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem
24
int x = 3; if (x > 1) if (x > 2) { if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); Old problem
25
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem
26
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem else w/out if Does not compile!
27
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem else w/out if Does not compile!
28
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem else w/out if Does not compile! The only solution, then, is to carefully draw the flowchart!
29
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem else w/out if Does not compile! The only solution, then, is to carefully draw the flowchart! On paper, or in your mind, it doesn’t matter. There really isn’t any reliable, uniform shortcut alternative to that.
30
int x = 3; if (x > 1) { if (x > 2) if (x > 3) System.out.println("one"); } else System.out.println("three"); else System.out.println("four"); New problem else w/out if Does not compile! The only solution, then, is to carefully draw the flowchart! On paper, or in your mind, it doesn’t matter. There really isn’t any reliable, uniform shortcut alternative to that.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.