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.

Slides:



Advertisements
Similar presentations
The Important Thing About By. The Important Thing About ******** The important thing about ***** is *****. It is true s/he can *****, *****, and *****.
Advertisements

ALGORITHMS AND FLOWCHARTS
For(int i = 1; i
Q1 Review. Other News US News top CS Universities global-universities/computer- science?int=994b08.
PROBLEM SOLVING TECHNIQUES
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
PSEUDOCODE & FLOW CHART
Fundamentals of Algorithms MCS - 2 Lecture # 4
This presentation includes custom animations. To view the animations, you must view the presentation in Slide Show mode and activeX controls must be allowed.
ECIV 301 Programming & Graphics Numerical Methods for Engineers Lecture 3 Programming and Software.
1 The first step in understanding pointers is visualizing what they represent at the machine level. In most modern computers, main memory is divided into.
Developing logic (Examples on algorithm and flowchart)
Boolean Expressions and If Flow of Control / Conditional Statements The if Statement Logical Operators The else Clause Block statements Nested if statements.
Functions of Management - Leading Coach Johnson – Fall 2008 Thanks Ms. Craddock-WCA.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
“Introduction to Programming With Java”
DAY OVERLOADING.  Overloading: allows for making several methods with the same name (method heading) which differ from each other in the type.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014 Office hours: Thursday 1300 – 1400hrs.
BIT 115: Introduction To Programming. 2 What’s Due When Listed in Course Schedule Let’s look at that now!
Lec 4: while loop and do-while loop. Review from last week if Statements if (num < 0.5){...println("heads"); } if –else Statements if (num < 0.5){...println("heads");
Programming: Simple Control Structures Part 2 – Repetition Alice.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Week 7 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Lec 21 More Fun with Arrays: For Loops. Agenda Some backfill for Lab 20: – Using an array in an applet or class – array instance variables – using Math.random()
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
The Fine Points of Conditionals. When squirrels get together for a party, they like to have cigars. A squirrel party is successful when the number of.
Week 7 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
"Digital Systems"1 7-segment Numeric display b a d g e c f.
3.1.3 Program Flow control Structured programming – SELECTION in greater detail.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Asking Permission 1.Agree, with condition 2.Agree, tell shortcoming 3.Decline, tell why 4.Decline, suggest other solution 5.Hedge Signer A: My lawn-mower.
Checkers A Matlab Project by Spenser Davison, Edward Dyakiw, Justin Pezzi, and Scott Wu.
Follow the same process as solving multi-step equations. Keep in mind that you want your equation to end up looking like: VARIABLE = NUMBER **It doesn’t.
Some Slides from Art Costa on Effective Questioning Challenge yourself to make thinking skill requirements specific to your students.
An Introduction to Programming with C++1 The Selection Structure Tutorial 6.
CS106X – Programming Abstractions in C++ Cynthia Bailey Lee CS2 in C++ Peer Instruction Materials by Cynthia Bailey Lee is licensed under a Creative Commons.
Learning Styles UTLDG-fHFE.
ECE Application Programming
Inheritance Based on slides by Ethan Apter
Section 3 Review Mr. Crone.
Selection (also known as Branching) Jumail Bin Taliba by
Week 4 - Wednesday CS 121.
Be A programmer in Steps
Friday, 10/4 Reminder: Open note vector quiz on Monday, 10/7
CSE 311 Foundations of Computing I
Numbering System TODAY AND TOMORROW 11th Edition
Programming: Simple Control Structures
إعداد المشرفة التربوية نجلاء الجارد
Programming: Simple Control Structures
1) C program development 2) Selection structure
Lec 4: while loop and do-while loop
Programming: Simple Control Structures
Process Automation: From models to code
Introduction to Flowcharts
Introduction to programming
Programming: Simple Control Structures
Lecture 7 Algorithm Design & Implementation. All problems can be solved by employing any one of the following building blocks or their combinations 1.
Haskell Dealing with impurity 8-Apr-19.
Selection Structures: Single-alternative
Graphing Linear Equations
EECE.2160 ECE Application Programming
Why we have Counterintuitive Memory Models
IAT 800 Foundations of Computational Art and Design
Chapter 5: The Selection Structure
AP Free Response Strategies
Haskell Dealing with impurity 29-May-19.
Haskell Dealing with impurity 28-Jun-19.
Programming: Simple Control Structures
Lec 21 More Fun with Arrays: For Loops
Presentation transcript:

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?

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.

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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!

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!

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!

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.

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.