Controlling Program Flow

Slides:



Advertisements
Similar presentations
Chapter 4: Control Structures I (Selection)
Advertisements

MONTEGO BAY HIGH SCHOOL INFORMATION TECHNOLOGY THE EXCEL IF FUNCTION.
Loops (Part 1) Computer Science Erwin High School Fall 2014.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
1 Controlling Script Flow! David Lash Chapter 3 Conditional Statements.
5-1 Flow of Control Recitation-01/25/2008  CS 180  Department of Computer Science  Purdue University.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Chapter 4 Loops and Character Manipulation Dr. Ali Can Takinacı İstanbul Technical University Faculty of Naval Architecture and Ocean Engineering İstanbul.
Flow of Control MINS298c Fall 1998 Chapter 9. Overview ABAP Programming Structures for: –Iteration –Decisions Control Flow –If … Then –Do & While loops.
16/27/ :53 PM6/27/ :53 PM6/27/ :53 PMLogic Control Structures Arithmetic Expressions Used to do arithmetic. Operations consist of +,
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
Geography 465 Assignments, Conditionals, and Loops.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Fac of Ene & Surveying U.S.Q.1 E0001 Computers in Engineering DO.... LOOP.
Problem Solving and Control Statements. Using Exit to Terminate Repetition Statements There are many forms of the Exit statement, designed to terminate.
1 © 2000 John Urrutia. All rights reserved. Qbasic Looping Statements & Formatted Output.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
CONTROLLING PROGRAM FLOW
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
Slide 3-1 CHAPTER 3 Conditional Statements Objectives To learn to use conditional test statements to compare numerical and string data values To learn.
1 Module 3 Conditional Statements. Objectives  Conditional test statements to compare numerical and string data values  Looping statements to repeat.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
© ABB University - 1 Revision C E x t e n d e d A u t o m a t i o n S y s t e m x A Chapter 11 Structured Text Course T314.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
Computer Science: A Structured Programming Approach Using C1 5-2 Two-Way Selection The decision is described to the computer as a conditional statement.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Copyright © 2003 Pearson Education, Inc. Slide 3-1 The Web Wizard’s Guide to PHP by David A. Lash.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Loops ( while and for ) CSE 1310 – Introduction to Computers and Programming Alexandra Stefan 1.
Selection Using IF THEN ELSE CASE Introducing Loops.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
Discussion 4 eecs 183 Hannah Westra.
Control Flow (Python) Dr. José M. Reyes Álamo.
LOGICAL CONTROL STRUCTURES (chp. 8)
CprE 185: Intro to Problem Solving (using C)
Chapter 4 Repetition Statements (loops)
Making Choices with if Statements
Sequence, Selection, Iteration The IF Statement
Chapter 4 C Program Control Part II
Python: Control Structures
Control Structures: Part 2
Topics The if Statement The if-else Statement Comparing Strings
( Iteration / Repetition / Looping )
Topics discussed in this section:
ITM 352 Flow-Control: Loops
CPS120: Introduction to Computer Science
Chapter 8 JavaScript: Control Statements, Part 2
Programming with PHP Part 2
Iteration: Beyond the Basic PERFORM
Program Flow Control Selection & repetition
Repetition Control Structure
` Structured Programming & Flowchart
Logical Operations In Matlab.
Three Special Structures – Case, Do While, and Do Until
Problem Solving and Control Statements
VB Decisions & Conditions
Controlling Program Flow
PowerShell Flow of Control Copyright © 2016 – Curt Hill.
Chapter 5 Decisions.
‘do’ and ‘for’ loops October 1, 2007 ComS 207: Programming I (in Java)
‘do’ and ‘for’ loops October 2, 2006 ComS 207: Programming I (in Java)
Presentation transcript:

Controlling Program Flow 091700

Topics Conditional Operators Logical Operators If Select Case Loops

Operators manipulate data by combining or computing results.

Math and String Operators Already Covered ( ) ^ * / \ MOD + - &

6 Conditional Operators = Equal to < Less than > Greater than <> Not equal (less than or greater than) <= Less than or equal to >= Greater than or equal to NOTE: Errors is textbook table 6.1

You can compare strings “S” < “s” “Kev” < “Kevin” ASCII table for character values Appendix C, page 888 IMPORTANT: The computer ultimately gives comparisons a TRUE or FALSE answer. print (1<2) print (1=2)

Like Operator Used for seeing if strings are similar Uses Wildcards: * ? # [characters] [!not these characters] print “Kevin” like “Ke*” print “Boot” “B??t” print “Beet” like “B??t” print “Employee 7” like “Employee #” NOTE: Wildcard comparison has to be AFTER the like operator. Book is misleading here.

Logical Operators And Or Xor Not

And …Statements If (varA = varB) And (varC < varD) then End if If True and True then Condition 1 AND Condition 2

Or …Statements If (varA = varB) Or (varC < varD) then End if If True Or True then Condition 1 AND Condition 2

Xor …Statements If (varA = varB) Xor (varC < varD) then End if If True Xor True then Condition 1 AND Condition 2

Not …Statements If Not((varA = varB) And (varC < varD)) then End if NEGATES a condition Use Sparingly!

Truth Table Condition Result AND TRUE FALSE OR XOR

Such a simple device… Computers only know: 1 or 0 ON or OFF Yes or No True or False We combine these choices to set the course of our computer program.

If then If (condition is true) then do this End if

If then Else If (condition is true) then do this Else do something else End If

If then ElseIf If (condition is true) then do this ElseIf (condition is true) then do something else Else do yet something else End If

Select Case Simpler, more logical than using several elses Select Case varAge Case Is <5 statements Case 5 Case 6 to 11 Case 12 to 13, 23 to 46, Is 65 Case Else End Select

For Next Loop Used for counting through a certain number of iterations (geek-speak for times). For Counter = 1 to 10 statements Next

Nesting Loops For outerCounter = 1 to 10 statements For innerCounter = 1 to 10 Next innerCounter Next outerCounter

Step value For counter = 0 to 10 step 2 statements Next

Step Values: negative For counter = 10 to 0 Step -1 statements Next

Do Loops Execute WHILE a condition is true, or UNTIL it is true Do While strAnswer=“yes” statements Loop

Do Loops Do While Loop condition Until

Do Loops Do While condition statements Loop Do statements Loop While condition Do Until condition statements Loop Do statements Loop Until condition

An early exit… Exit Sub Exit Function Exit For Exit Do Use sparingly - It is most clear to have one exit for a program segment