IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

Lesson 5 - Decision Structure By: Dan Lunney
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Compunet Corporation1 Programming with Visual Basic.NET Selection Structure If-Else Week 4 Tariq Ibn Aziz.
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.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Control Structures: Part 2. Introduction Essentials of Counter-Controlled Repetition For / Next Repetition Structure Examples Using the For / Next Structure.
Control Structures: Getting Started Sequence and Selection also arithmetic operators, data types, logical operators.
Section 3 - Selection and Repetition Constructs. Control Structures 1. Sequence 2. Selection 3. Repetition.
For…Next : Nested Loop X= 0 For i = 0 To 4 For j = 0 To i-1 X=X+(i+j-1) Next j Next i How many times the inner loop is executed? What is x at the end of.
Jaeki Song ISQS6337 JAVA Lecture 04 Control Structure - Selection, and Repetition -
CPS120: Introduction to Computer Science Decision Making in Programs.
ENGR 112 Decision Structures.
1. We’ve learned that our programs are read by the compiler in order, from top to bottom, just as they are written The order of statement execution is.
CONTROL STRUCTURE The if, elseif, and else & switch Statements 1.
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
Control Structures By Shyam Gurram. Control Structure In this chapter we have two different types of structures. Conditional Structure Iterative Control.
sequence of execution of high-level statements
Program Flow Control - Looping Addis Ababa Institute of Technology Yared Semu April 2012.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
CS285 Visual Basic 2 Department of Computing UniS 1 Statements in Visual Basic A statement is the fundamental syntactical element of a program smallest.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Control Structures sequence of execution of high-level statements.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
© 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.
Introduction to Problem Solving and Control Statements.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
Chapter 3 Control Structures. The If…Then Statement The If…Then statement is a Decision statement = that executes a set of statements when a condition.
Control Flow Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Programming Logic and Design, Introductory, Fourth Edition1 Understanding the Three Basic Structures Structure: a basic unit of programming logic Any program.
CPS120: Introduction to Computer Science Decision Making in Programs.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Program Structures Chapter 5. 5 Branching Allows different code to execute based on a conditional test. if, if-else, and switch statements.
CPS120: Introduction to Computer Science Decision Making in Programs.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Conditional Statements A conditional statement lets us choose which statement will be executed next Conditional statements give us the power to make basic.
Programming Logic and Design Fourth Edition, Introductory Chapter 2 Understanding Structure.
IST 210: PHP Logic IST 210: Organization of Data IST2101.
Visual Basic 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.-Edited By Maysoon Al-Duwais1.
Control Flow (Python) Dr. José M. Reyes Álamo.
Chapter 5- Control Structures: Part 2
Visual Basic 6 (VB6) Data Types, And Operators
The switch Statement, and Introduction to Looping
Control Structures: Part 2
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2B) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
Expressions and Control Flow in JavaScript
` Structured Programming & Flowchart
Introduction to Problem Solving and Control Statements
Three Special Structures – Case, Do While, and Do Until
Problem Solving and Control Statements
Computer Science Core Concepts
Controlling Program Flow
Case & Repetitive Statements
Program Flow.
ASP control structure BRANCHING STATEMENTS
Presentation transcript:

IS437: Fall 2004 Instructor: Dr. Boris Jukic Program Flow Control: Decisions and Conditions (Branching) Controlled Repetition (Looping)

Structure of computer languages data types (variables & constants) assignment flow control - branching - looping input/output

If-then-else If condition Then …. End If If condition Then …. Else …. End If If condition1 Then …. ElseIf condition2 Then …. Else …. End If

Relational Operators = equality > greater than < less than not equals >= greater than or equal to <= less than or equal to

Logical operators and (both are true) - e.g., a and b or (at least one is true) - e.g., a or b xor (exclusive or, only one is true) - e.g., a xor b not (negation) e.g., (a or b) and (not c)

If (asset > 5000) and (debt <= 5000) then label1.text = “I can pay off my debt” End if Dim taxexempt as Boolean Dim age as integer …. If (taxexempt) xor (age < = 18) then …. ‘code that applies to people are either taxexempt or younger than 18 …. End if Logical operators: examples

Select-Case Statement Dim Name as string …. Select Case Name Case “Fred” label1.text = “Hello Fred” Case “Jane” label1.text = “Hello Jane” Case Else label1.text = “Hello! Anyone Home?” End Select

Dim x as integer = 50 Select Case Integer.Parse(guessNumberTextBox.text) Case Is < 1 label1.text = “Way too low!” Case Is > 100 label1.text = “Way too high!” Case Is > x label1.text = “Too high!” Case Is < x label1.text = “Too low!” Case x label1.text = “You got it!” End Select If more than one case matches the test expression, only the statement block associated with the first matching case will execute. Select-Case Statement

Select Case Choice Case 1, 3, 7 …. Case 2, 4, 5, 6, 8 …. Case Else …. End Select Select-Case Statement

Select Case Choice Case 1 to 3, 7 to 10 …. Case 4 to 6 …. Case Else …. End Select Select-Case Statement

Loops For-Next Loops Do-Loops While-Loops

For - Next Loops For I = 1 to 5 …. Next I For J = 3 to 7 Step 2 …. Next J For I = 10 to 1 Step -2 …. Next I For M = 1 to N …. If x > y then Exit For End if Next M

Nested For-Next Loops For I = x to y …. For J = m to n …. Next J …. Next I For two dimensional data structures

Do-Loops Condition pre-tested Do-While loop Do-Until loop Condition post-tested Do-loop While Do-loop Until

Dim hungry as Boolean …. Do While hungry …. Loop Dim hungry as Boolean …. Do Until Not hungry …. Loop Dim hungry as Boolean …. Do …. Loop While hungry ‘this loop is executed as least once Dim hungry as Boolean …. Do …. Loop Until not hungry ‘this loop is executed as least once Do-Loops: pre-test vs. post-test

Exit-Do Do While hungry ….. if tired then exit do end if …. Loop