Selection If Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional.

Slides:



Advertisements
Similar presentations
Working With Algorithm and Flowcharts
Advertisements

Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
Selection Process If … then … else.... Condition Process 2 Process 1 Y.
3 Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. Conditions can be formed using the.
1 Flowchart If – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem
Lesson 5 - Decision Structure By: Dan Lunney
Pascal Programming Today Chapter 4 1 »Conditional statements allow the execution of one of a number of possible operations. »Conditional statements include:
CHAPTER 5: LOOP STRUCTURES Introduction to Computer Science Using Ruby (c) 2012 Ophir Frieder et al.
ITEC113 Algorithms and Programming Techniques
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 3, Lecture 2.
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Guide To UNIX Using Linux Third Edition
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
CSC103: Introduction to Computer and Programming
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Five More on the Selection Structure.
Branching and Conditions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
C Lecture Notes 1 Structured Program Development.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
 Learn about control structures  Examine relational and logical operators  Explore how to form and evaluate logical (Boolean) expressions  Learn how.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Programming, an introduction to Pascal
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering Problem Solving and Logic.
 2000 Deitel & Associates, Inc. All rights reserved. Chapter 10 - JavaScript/JScript: Control Structures II Outline 10.1Introduction 10.2Essentials of.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
5.04 Apply Decision Making Structures
CPS120: Introduction to Computer Science Decision Making in Programs.
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Introduction to Programming Python Lab 7: if Statement 19 February PythonLab7 lecture slides.ppt Ping Brennan
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
Flow Charts And Pseudo Codes Grade 12. An algorithm is a complete step-by- step procedure for solving a problem or accomplishing a task.
Control Flow (Python) Dr. José M. Reyes Álamo.
REPETITION CONTROL STRUCTURE
Repetition Structures Chapter 9
Introduction to Computing
Unit 2 Smarter Programming.
Numbering System TODAY AND TOMORROW 11th Edition
Programming Fundamentals
Making Decisions in a Program
Topics The if Statement The if-else Statement Comparing Strings
Lesson 8: Boolean Expressions and "if" Statements
Computers & Programming Languages
Structured Program
1) C program development 2) Selection structure
ME 142 Engineering Computation I
Visual Basic – Decision Statements
Selection Statements.
Microsoft Visual Basic 2005: Reloaded Second Edition
Developing a Program.
Structural Program Development: If, If-Else
Introduction to Programming
Presentation transcript:

Selection If

Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional symbols Used to represent the flow of control of a computer program

Sample Flowchart

Basic Elements in Flowchart Terminal BoxProcess Box Decision BoxFlow line

Another Sample Turn on the computer Wait until login screen appears Press Ctrl-Atl-Delete Enter your password Flow of control of turn on and login windows NT Start End

Meaning of Flowchart Elements Process Box: Action that will be taken Flow Line: The direction of line indicates the next state Decision Box: A true-or-false decision, the next state depends on the result of the decision. Terminator Box: Start and end of the flow

Relation Between Pseudo-code and Flowchart Both pseudo-code and flowchart descript the steps and flow to solve a problem You can convert a pseudo-code to flowchart and vice versa

Relation Between Pseudo-code and Flowchart Turn on the computer Wait until login screen appears Press Ctrl-Atl-Delete Enter your password Start End 1. Turn on the computer 2. Wait until login screen appears 3. Press Ctrl-Atl- Delete 4. Enter your password

Decision Box One of the elements in flowchart Contains a true or false statement The next state depends on the value of the statement

Example Start Before 1:00 pm ? Stand Up Good Morning Mr. Wong Good Afternoon Mr. Wong truefalse End

Pseudo-code Version Stand-up If the time is before 1:00 pm Say “Good morning Mr. Wong” Else, say “Good afternoon Mr. Wong” Start Before 1:00 pm ? Stand Up Good Morning Mr. Wong Good Afternoon Mr. Wong truefalse End

If…then…else Statement Syntax: if then else if, then, else are reserved words Remember! no comma after statement-1 and before else else statement can be omitted

Example program positive; var input : integer; begin write ( ‘Please enter a number: ‘ ); readln ( input ); if input >= 0 then writeln ( ‘It is a positive number’ ) else writeln ( ‘It is a negative number’ ) end.

Compound statements Compound statement means one or more statements bracketed by begin and end The statement part itself is also a compound statement The then part and else part of if…then…else statement should contain one statement only If you need more then one statement in any of these parts, you have to use compound statement

Example if x > 0 then begin y := x + 1; writeln ( x ); end ……

Nested if statements if statement inside the then part or the else part of another if statement You are reminded to write program with proper indentation