Introductory Notes: Condition Statements

Size: px
Start display at page:

Download "Introductory Notes: Condition Statements"

Transcription

1 Brigham Young University - Idaho College of Physical Sciences and Engineering Department of Mechanical Engineering Introductory Notes: Condition Statements The simplest of all computer programs perform a set of instructions sequentially, starting at the top of the program and proceeding down one line at a time until the end of the program is reached. Most programs, however, require that decisions may be during the time of execution. This may require testing conditions to determine what procedure to perform next, skipping over some statements, and executing some statements multiple times. In Excel, we were introduced to this concept when we learned how to use the IF function. We will extend those concepts in the class. A quick summary of the commands we ll be working with is provided below. More detailed notes and examples from the online help files have also been included following the summary section. Relational Operators Relational or comparison operators are used in expressions to perform a test. They are most commonly used in conjunction with an IF statement. Common relational operators include: < less than <= less than or equal to > greater than >= greater than or equal to <> not equal to = equal to Logical Operators Logical operators are used in complex expressions to perform a test. In essence they are used to check for the validity of multiple conditions being met. Common logical operators include AND, OR, and NOT: AND returns true if all parts of the expression are true, otherwise returns false OR returns true if any part of the expression is true, otherwise returns false NOT returns true if expression is false, returns false if expression is true You may need to use parenthesis to control order of operation for more complex expressions.

2 If-Then-Else Statement If statements are used to execute a statement or block of statements when a condition is true. Logical and relational operators are used to form expressions which are evaluated as either true or false. Syntax for the If statement is as follows: If condition Then [statements ] [ElseIf condition Then] [statements ] [Else] [statements ] When a condition is true, VBA executes the corresponding block of statements. Execution of the program is then transferred to the end of the If structure. A one line version of the is also available for cases where a single statement is to be executed: If condition Then statement GoTo A GoTo statement offers a straightforward means of changing the program flow. This statement transfers program control to a new statement, identified by a label. A label is a text string followed by a colon. In general avoid the use of GoTo, using it only when you have no other way to perform an action. In practice, the only time you really need to use a GoTo statement if for error trapping.

3 Online Help File Notes Not Operator Used to perform logical negation on an expression. Syntax result = Not expression The Not operator syntax has these parts: Part result expression Description Required; any numeric variable. Required; any expression. Remarks The following table illustrates how result is determined: If expression is True False Null Then result is False True Null In addition, the Not operator inverts the bit values of any variable and sets the corresponding bit in result according to the following table: If bit in expression is o Then bit in result is Example This example uses the Not operator to perform logical negation on an expression. Dim A, B, C, D, MyCheck A = 10: B = 8: C = 6: D = Null ' Initialize variables. MyCheck = Not(A > B) ' Returns False. MyCheck = Not(B > A) ' Returns True. MyCheck = Not(C > D) ' Returns Null. MyCheck = Not A ' Returns -11 (bitwise comparison).

4 Or Operator Used to perform a logical disjunction on two expressions. Syntax result = expression1 Or expression2 The Or operator syntax has these parts: Part result expression1 expression2 Description Required; any numeric variable. Required; any expression. Required; any expression. Remarks If either or both expressions evaluate to True, result is True. The following table illustrates how result is determined: If expression1 is And expression2 is Then result is True True True True False True True Null True False True True False False False False Null Null Null True True Null False Null Null Null Null The Or operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table: If bit in expression1 is And bit in expression2 is Then result is Example This example uses the Or operator to perform logical disjunction on two expressions. Dim A, B, C, D, MyCheck A = 10: B = 8: C = 6: D = Null ' Initialize variables. MyCheck = A > B Or B > C ' Returns True. MyCheck = B > A Or B > C ' Returns True. MyCheck = A > B Or B > D ' Returns True. MyCheck = B > D Or B > A ' Returns Null. MyCheck = A Or B ' Returns 10 (bitwise comparison).

5 And Operator Used to perform a logical conjunction on two expressions. Syntax result = expression1 And expression2 The And operator syntax has these parts: Part result expression1 expression2 Description Required; any numeric variable. Required; any expression. Required; any expression. Remarks If both expressions evaluate to True, result is True. If either expression evaluates to False, result is False. The following table illustrates how result is determined: If expression1 is And expression2 is The result is True True True True False False True Null Null False True False False False False False Null False Null True Null Null False False Null Null Null The And operator also performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table: If bit in expression1 is And bit in expression2 is The result is Example This example uses the And operator to perform a logical conjunction on two expressions. Dim A, B, C, D, MyCheck A = 10: B = 8: C = 6: D = Null ' Initialize variables. MyCheck = A > B And B > C ' Returns True. MyCheck = B > A And B > C ' Returns False. MyCheck = A > B And B > D ' Returns Null. MyCheck = A And B ' Returns 8 (bitwise comparison).

6 If...Then...Else Statement Conditionally executes a group of statements, depending on the value of an expression. Syntax If condition Then [statements] [Else elsestatements] Or, you can use the block form syntax: If condition Then [statements] [ElseIf condition-n Then [elseifstatements]... [Else [elsestatements]] The If...Then...Else statement syntax has these parts: Part condition statements condition-n elseifstatements elsestatements Description Required. One or more of the following two types of expressions: A numeric expression or string expression that evaluates to True or False. If condition is Null, condition is treated as False. An expression of the form TypeOf objectname Is objecttype. The objectname is any object reference and objecttype is any valid object type. The expression is True if objectname is of the object type specified by objecttype; otherwise it is False. Optional in block form; required in single-line form that has no Else clause. One or more statements separated by colons; executed if condition is True. Optional. Same as condition. Optional. One or more statements executed if associated condition-n is True. Optional. One or more statements executed if no previous condition or condition-n expression is True. Remarks You can use the single-line form (first syntax) for short, simple tests. However, the block form (second syntax) provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug. Note With the single-line form, it is possible to have multiple statements executed as the result of an If...Then decision. All statements must be on the same line and separated by colons, as in the following statement: If A > 10 Then A = A + 1 : B = B + A : C = C + B A block form If statement must be the first statement on a line. The Else, ElseIf, and parts of the statement can have only a line number or line label preceding them. The block If must end with an statement. To determine whether or not a statement is a block If, examine what follows the Then keyword. If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement. The Else and ElseIf clauses are both optional. You can have as many ElseIf clauses as you want in a block If, but none can appear after an Else clause. Block If statements can be nested; that is, contained within one another. When executing a block If (second syntax), condition is tested. If condition is True, the statements following Then are executed. If condition is False, each ElseIf condition (if any) is evaluated in turn. When a True condition is found, the statements immediately following the associated Then are executed. If none of the ElseIf conditions are True (or if there are no ElseIf clauses), the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following.

7 Tip Select Case may be more useful when evaluating a single expression that has several possible actions. However, the TypeOf objectname Is objecttype clause can't be used with the Select Case statement. Note TypeOf cannot be used with hard data types such as Long, Integer, and so forth other than Object. Example This example shows both the block and single-line forms of the If...Then...Else statement. It also illustrates the use of If TypeOf...Then...Else. Dim Number, Digits, MyString Number = 53 If Number < 10 Then Digits = 1 ElseIf Number < 100 Then ' Initialize variable. ' Condition evaluates to True so the next statement is executed. Else Digits = 2 Digits = 3 ' Assign a value using the single-line form of syntax. If Digits = 1 Then MyString = "One" Else MyString = "More than one" Use If TypeOf construct to determine whether the Control passed into a procedure is a text box. Sub ControlProcessor(MyControl As Control) If TypeOf MyControl Is CommandButton Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is CheckBox Then Debug.Print "You passed in a " & TypeName(MyControl) ElseIf TypeOf MyControl Is TextBox Then Debug.Print "You passed in a " & TypeName(MyControl) End Sub

8 Using If...Then...Else Statements You can use the If...Then...Else statement to run a specific statement or a block of statements, depending on the value of a condition. If...Then...Else statements can be nested to as many levels as you need. However, for readability, you may want to use a Select Case statement rather than multiple levels of nested If...Then...Else statements. Running Statements if a Condition is True To run only one statement when a condition is True, use the single-line syntax of the If...Then...Else statement. The following example shows the single-line syntax, omitting the Else keyword: Sub FixDate() End Sub mydate = #2/13/95# If mydate < Now Then mydate = Now To run more than one line of code, you must use the multiple-line syntax. This syntax includes the statement, as shown in the following example: Sub AlertUser(value as Long) End Sub If value = 0 Then AlertLabel.ForeColor = "Red" AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True Running Certain Statements if a Condition is True and Running Others if It's False Use an If...Then...Else statement to define two blocks of executable statements: one block runs if the condition is True, the other block runs if the condition is False. Sub AlertUser(value as Long) If value = 0 Then Else End Sub AlertLabel.ForeColor = vbred AlertLabel.Font.Bold = True AlertLabel.Font.Italic = True AlertLabel.Forecolor = vbblack AlertLabel.Font.Bold = False AlertLabel.Font.Italic = False

9 Testing a Second Condition if the First Condition is False You can add ElseIf statements to an If...Then...Else statement to test a second condition if the first condition is False. For example, the following function procedure computes a bonus based on job classification. The statement following the Else statement runs if the conditions in all of the If and ElseIf statements are False. Function Bonus(performance, salary) If performance = 1 Then Bonus = salary * 0.1 ElseIf performance = 2 Then Bonus = salary * 0.09 ElseIf performance = 3 Then Else End Function Bonus = salary * 0.07 Bonus = 0

10 GoTo Statement Branches unconditionally to a specified line within a procedure. Syntax GoTo line The required line argument can be any line label or line number. Remarks GoTo can branch only to lines within the procedure where it appears. Note Too many GoTo statements can make code difficult to read and debug. Use structured control statements (Do...Loop, For...Next, If...Then...Else, Select Case) whenever possible. Example This example uses the GoTo statement to branch to line labels within a procedure. Sub GotoStatementDemo() Dim Number, MyString Number = 1 ' Initialize variable. ' Evaluate Number and branch to appropriate label. If Number = 1 Then GoTo Line1 Else GoTo Line2 Line1: MyString = "Number equals 1" GoTo LastLine ' Go to LastLine. Line2: ' The following statement never gets executed. MyString = "Number equals 2" LastLine: Debug.Print MyString ' Print "Number equals 1" in ' the Immediate window. End Sub

ME 142 Engineering Computation I. Condition Statements

ME 142 Engineering Computation I. Condition Statements ME 142 Engineering Computation I Condition Statements Key Concepts Relational Operators Logical Operators If-Then-Else Statement GoTo Statement Worksheetfunction.xxx Organization/Name Changes Programming

More information

Statements and Operators

Statements and Operators Statements and Operators Old Content - visit altium.com/documentation Mod ifi ed by Rob Eva ns on Feb 15, 201 7 Parent page: EnableBasic Enable Basic Statements Do...Loop Conditional statement that repeats

More information

Control Structures. CIS 118 Intro to LINUX

Control Structures. CIS 118 Intro to LINUX Control Structures CIS 118 Intro to LINUX Basic Control Structures TEST The test utility, has many formats for evaluating expressions. For example, when given three arguments, will return the value true

More information

7 Control Structures, Logical Statements

7 Control Structures, Logical Statements 7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,

More information

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6)

DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) Technology & Information Management Instructor: Michael Kremer, Ph.D. Database Program: Microsoft Access Series DATABASE AUTOMATION USING VBA (ADVANCED MICROSOFT ACCESS, X405.6) AGENDA 3. Executing VBA

More information

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL)

PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 3 Database Programming PROCEDURAL DATABASE PROGRAMMING ( PL/SQL AND T-SQL) AGENDA 3. Declaring Variables/Constants 4. Flow Control

More information

Creating If/Then/Else Routines

Creating If/Then/Else Routines 10 ch10.indd 147 Creating If/Then/Else Routines You can use If/Then/Else routines to give logic to your macros. The process of the macro proceeds in different directions depending on the results of an

More information

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4.

Introduction to Visual Basic and Visual C++ Arithmetic Expression. Arithmetic Expression. Using Arithmetic Expression. Lesson 4. Introduction to Visual Basic and Visual C++ Arithmetic Expression Lesson 4 Calculation I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Arithmetic Expression Using Arithmetic Expression Calculations

More information

Flow Control: Branches and loops

Flow Control: Branches and loops Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the

More information

Control Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur

Control Structures. Code can be purely arithmetic assignments. At some point we will need some kind of control or decision making process to occur Control Structures Code can be purely arithmetic assignments At some point we will need some kind of control or decision making process to occur C uses the if keyword as part of it s control structure

More information

Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc.

Chapter 2 REXX STATEMENTS. SYS-ED/ Computer Education Techniques, Inc. Chapter 2 REXX STATEMENTS SYS-ED/ Computer Education Techniques, Inc. Objectives You will learn: Variables. REXX expressions. Concatenation. Conditional programming and flow of control. Condition traps.

More information

Chapter 4 The If Then Statement

Chapter 4 The If Then Statement The If Then Statement Conditional control structure, also called a decision structure Executes a set of statements when a condition is true The condition is a Boolean expression For example, the statement

More information

Control Structures. Control Structures 3-1

Control Structures. Control Structures 3-1 3 Control Structures One ship drives east and another drives west With the selfsame winds that blow. Tis the set of the sails and not the gales Which tells us the way to go. Ella Wheeler Wilcox This chapter

More information

Flow of Control. Flow of control The order in which statements are executed. Transfer of control

Flow of Control. Flow of control The order in which statements are executed. Transfer of control 1 Programming in C Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed

V2 2/4/ Ch Programming in C. Flow of Control. Flow of Control. Flow of control The order in which statements are executed Programming in C 1 Flow of Control Flow of control The order in which statements are executed Transfer of control When the next statement executed is not the next one in sequence 2 Flow of Control Control

More information

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University Unit 1 Programming Language and Overview of C 1. State whether the following statements are true or false. a. Every line in a C program should end with a semicolon. b. In C language lowercase letters are

More information

CHAD Language Reference Manual

CHAD Language Reference Manual CHAD Language Reference Manual INTRODUCTION The CHAD programming language is a limited purpose programming language designed to allow teachers and students to quickly code algorithms involving arrays,

More information

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials Fundamentals We build up instructions from three types of materials Constants Expressions Fundamentals Constants are just that, they are values that don t change as our macros are executing Fundamentals

More information

Decision Making -Branching. Class Incharge: S. Sasirekha

Decision Making -Branching. Class Incharge: S. Sasirekha Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

Introduction to C Programming

Introduction to C Programming 1 2 Introduction to C Programming 2.6 Decision Making: Equality and Relational Operators 2 Executable statements Perform actions (calculations, input/output of data) Perform decisions - May want to print

More information

5. Control Statements

5. Control Statements 5. Control Statements This section of the course will introduce you to the major control statements in C++. These control statements are used to specify the branching in an algorithm/recipe. Control statements

More information

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration STATS 507 Data Analysis in Python Lecture 2: Functions, Conditionals, Recursion and Iteration Functions in Python We ve already seen examples of functions: e.g., type()and print() Function calls take the

More information

You can change this way of execution by control structures branching or decision structures

You can change this way of execution by control structures branching or decision structures Declaration of constants Constants are variables which do not change their value during the execution of the program (UDF). Constants are used to keep the programming structure clear and to avoid tedious

More information

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control. Part 5 Intel x86 Jump Instructions Control Logic Fly over code Operations: Program Flow Control Operations: Program Flow Control Unlike high-level languages, processors don't have fancy expressions or

More information

DECISION MAKING STATEMENTS

DECISION MAKING STATEMENTS DECISION MAKING STATEMENTS If, else if, switch case These statements allow the execution of selective statements based on certain decision criteria. C language provides the following statements: if statement

More information

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type >

VBA Handout. References, tutorials, books. Code basics. Conditional statements. Dim myvar As <Type > VBA Handout References, tutorials, books Excel and VBA tutorials Excel VBA Made Easy (Book) Excel 2013 Power Programming with VBA (online library reference) VBA for Modelers (Book on Amazon) Code basics

More information

MATLAB provides several built-in statements that allow for conditional behavior if/elseif/else switch menu

MATLAB provides several built-in statements that allow for conditional behavior if/elseif/else switch menu Chapter 3 What we have done so far: Scripts/Functions have executed all commands in order, not matter what What we often need: A piece of code that executes a series of commands, if and only if some condition

More information

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control.

Intel x86 Jump Instructions. Part 5. JMP address. Operations: Program Flow Control. Operations: Program Flow Control. Part 5 Intel x86 Jump Instructions Control Logic Fly over code Operations: Program Flow Control Operations: Program Flow Control Unlike high-level languages, processors don't have fancy expressions or

More information

(Refer Slide Time: 01:12)

(Refer Slide Time: 01:12) Internet Technology Prof. Indranil Sengupta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture No #22 PERL Part II We continue with our discussion on the Perl

More information

C/C++ Programming for Engineers: Matlab Branches and Loops

C/C++ Programming for Engineers: Matlab Branches and Loops C/C++ Programming for Engineers: Matlab Branches and Loops John T. Bell Department of Computer Science University of Illinois, Chicago Review What is the difference between a script and a function in Matlab?

More information

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead.

Rule 1-3: Use white space to break a function into paragraphs. Rule 1-5: Avoid very long statements. Use multiple shorter statements instead. Chapter 9: Rules Chapter 1:Style and Program Organization Rule 1-1: Organize programs for readability, just as you would expect an author to organize a book. Rule 1-2: Divide each module up into a public

More information

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029

Programming Basics and Practice GEDB029 Decision Making, Branching and Looping. Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Programming Basics and Practice GEDB029 Decision Making, Branching and Looping Prof. Dr. Mannan Saeed Muhammad bit.ly/gedb029 Decision Making and Branching C language possesses such decision-making capabilities

More information

1. Description of RBbasic2K4 Lite Program

1. Description of RBbasic2K4 Lite Program 1. Description of RBbasic2K4 Lite Program In this paragraph, let's study the commands using at RBbasic2k4. It is based on the previous BASIC commands. You should know each command's function and use method

More information

Flow Control. CSC215 Lecture

Flow Control. CSC215 Lecture Flow Control CSC215 Lecture Outline Blocks and compound statements Conditional statements if - statement if-else - statement switch - statement? : opertator Nested conditional statements Repetitive statements

More information

Access VBA programming

Access VBA programming Access VBA programming TUTOR: Andy Sekiewicz MOODLE: http://moodle.city.ac.uk/ WEB: www.staff.city.ac.uk/~csathfc/acvba The DoCmd object The DoCmd object is used to code a lot of the bread and butter operations

More information

Visual Basic Course Pack

Visual Basic Course Pack Santa Monica College Computer Science 3 Visual Basic Course Pack Introduction VB.NET, short for Visual Basic.NET is a language that was first introduced by Microsoft in 1987. It has gone through many changes

More information

Decision Making in C

Decision Making in C Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed

More information

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script.

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script. LESSON 3 Flow Control In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script. In this chapter we ll look at two types of flow control:

More information

The Fortran Basics. Handout Two February 10, 2006

The Fortran Basics. Handout Two February 10, 2006 The Fortran Basics Handout Two February 10, 2006 A Fortran program consists of a sequential list of Fortran statements and constructs. A statement can be seen a continuous line of code, like b=a*a*a or

More information

CPSC 203 Extra review and solutions

CPSC 203 Extra review and solutions CPSC 203 Extra review and solutions Multiple choice questions: For Questions 1 6 determine the output of the MsgBox 1) x = 12 If (x > 0) Then s = s & "a" s = s & "b" a. a b. b c. s d. ab e. None of the

More information

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine.

ADVANTAGES. Via PL/SQL, all sorts of calculations can be done quickly and efficiently without use of Oracle engine. 1 PL/SQL INTRODUCTION SQL does not have procedural capabilities. SQL does not provide the programming techniques of condition checking, looping and branching that is required for data before permanent

More information

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

More information

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the

More information

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS Objectives By the end of this section you should be able to:

More information

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements

CS 199 Computer Programming. Spring 2018 Lecture 5 Control Statements CS 199 Computer Programming Spring 2018 Lecture 5 Control Statements Control Structures 3 control structures Sequence structure Programs executed sequentially by default Branch structure Unconditional

More information

Structure of Programming Languages Lecture 5

Structure of Programming Languages Lecture 5 Structure of Programming Languages Lecture 5 CSCI 6636 4536 June, 2017 CSCI 6636 4536 Lecture 10... 1/16 June, 2017 1 / 16 Outline 1 Expressions and Evaluation 2 Control Structures Conditionals Repetition

More information

Information Science 1

Information Science 1 Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control

More information

CS Introduction to Data Structures How to Parse Arithmetic Expressions

CS Introduction to Data Structures How to Parse Arithmetic Expressions CS3901 - Introduction to Data Structures How to Parse Arithmetic Expressions Lt Col Joel Young One of the common task required in implementing programming languages, calculators, simulation systems, and

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

DECISION CONTROL AND LOOPING STATEMENTS

DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of

More information

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering Computer Programming ECIV 2303 Chapter 6 Programming in MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering 1 Introduction A computer program is a sequence of computer

More information

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE

AIS Cube [THE BLAZINGCORE SERIES] LANGUAGE REFERENCE AIS Cube LANGUAGE REFERENCE [THE BLAZINGCORE SERIES] With superior number crunching abilities and peripheral handling on our custom embedded OS, Rapid prototyping is now easy... and blazing fast. Sonata

More information

CHAPTER : 9 FLOW OF CONTROL

CHAPTER : 9 FLOW OF CONTROL CHAPTER 9 FLOW OF CONTROL Statements-Statements are the instructions given to the Computer to perform any kind of action. Null Statement-A null statement is useful in those case where syntax of the language

More information

Lesson 04. Control Structures I : Decision Making. MIT 31043, VISUAL PROGRAMMING By: S. Sabraz Nawaz

Lesson 04. Control Structures I : Decision Making. MIT 31043, VISUAL PROGRAMMING By: S. Sabraz Nawaz Lesson 04 Control Structures I : Decision Making MIT 31043, VISUAL PROGRAMMING Senior Lecturer in MIT Department of MIT Faculty of Management and Commerce South Eastern University of Sri Lanka Decision

More information

do fifty two: Language Reference Manual

do fifty two: Language Reference Manual do fifty two: Language Reference Manual Sinclair Target Jayson Ng Josephine Tirtanata Yichi Liu Yunfei Wang 1. Introduction We propose a card game language targeted not at proficient programmers but at

More information

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan DATA 301 Introduction to Data Analytics Microsoft Excel VBA Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca DATA 301: Data Analytics (2) Why Microsoft Excel Visual Basic

More information

Learning the Language - V

Learning the Language - V Learning the Language - V Fundamentals We now have locations to store things so we need a way to get things into those storage locations To do that, we use assignment statements Deja Moo: The feeling that

More information

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos.

Before We Begin. Introduction to Computer Use II. Overview (1): Winter 2006 (Section M) CSE 1530 Winter Bill Kapralos. Winter 2006 (Section M) Topic E: Subprograms Functions and Procedures Wednesday, March 8 2006 CSE 1530, Winter 2006, Overview (1): Before We Begin Some administrative details Some questions to consider

More information

Unit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop

Unit 7. Lesson 7.1. Loop. For Next Statements. Introduction. Loop Loop Unit 7 Loop Introduction So far we have seen that each instruction is executed once and once only. Some time we may require that a group of instructions be executed repeatedly, until some logical

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

ENGR PBASIC programming

ENGR PBASIC programming ENGR 1100 PBASIC programming Variables Why variables? To store values, Why store variables? To count, Why count? To control and keep track of the number of times something happens Variables Variables can

More information

TED Language Reference Manual

TED Language Reference Manual 1 TED Language Reference Manual Theodore Ahlfeld(twa2108), Konstantin Itskov(koi2104) Matthew Haigh(mlh2196), Gideon Mendels(gm2597) Preface 1. Lexical Elements 1.1 Identifiers 1.2 Keywords 1.3 Constants

More information

d2vbaref.doc Page 1 of 22 05/11/02 14:21

d2vbaref.doc Page 1 of 22 05/11/02 14:21 Database Design 2 1. VBA or Macros?... 2 1.1 Advantages of VBA:... 2 1.2 When to use macros... 3 1.3 From here...... 3 2. A simple event procedure... 4 2.1 The code explained... 4 2.2 How does the error

More information

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures. Lecture 4 COP 3014 Fall September 18, 2017 Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

More information

Software Design & Programming I

Software Design & Programming I Software Design & Programming I Starting Out with C++ (From Control Structures through Objects) 7th Edition Written by: Tony Gaddis Pearson - Addison Wesley ISBN: 13-978-0-132-57625-3 Chapter 4 Making

More information

SMS 3515: Scientific Computing. Sem /2015

SMS 3515: Scientific Computing. Sem /2015 s s SMS 3515: Scientific Computing Department of Computational and Theoretical Sciences, Kulliyyah of Science, International Islamic University Malaysia. Sem 1 2014/2015 The if s that are conceptually

More information

The High-Powered Database The Whole Team Can Use. USING LOTUSSCRIPT IN APPROACH

The High-Powered Database The Whole Team Can Use. USING LOTUSSCRIPT IN APPROACH E.D.I.T.I.O.N The High-Powered Database The Whole Team Can Use. USING LOTUSSCRIPT IN APPROACH Under the copyright laws, neither the documentation nor the software may be copied, photocopied, reproduced,

More information

OpenOffice.org 3.2 BASIC Guide

OpenOffice.org 3.2 BASIC Guide OpenOffice.org 3.2 BASIC Guide Copyright The contents of this document are subject to the Public Documentation License. You may only use this document if you comply with the terms of the license. See:

More information

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax

Scheme Tutorial. Introduction. The Structure of Scheme Programs. Syntax Scheme Tutorial Introduction Scheme is an imperative language with a functional core. The functional core is based on the lambda calculus. In this chapter only the functional core and some simple I/O is

More information

Not For Sale. Using and Writing Visual Basic for Applications Code. Creating VBA Code for the Holland Database. Case Belmont Landscapes

Not For Sale. Using and Writing Visual Basic for Applications Code. Creating VBA Code for the Holland Database. Case Belmont Landscapes Objectives Tutorial 11 Session 11.1 Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event procedure Create a function

More information

Visual Basic 2010 How to Program by Pearson Education, Inc. All Rights Reserved.

Visual Basic 2010 How to Program by Pearson Education, Inc. All Rights Reserved. Visual Basic 2010 How to Program Before writing a program to solve a problem, you should have a thorough understanding of the problem and a carefully planned approach. When writing a program, it s also

More information

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB SECTION 2: PROGRAMMING WITH MATLAB MAE 4020/5020 Numerical Methods with MATLAB 2 Functions and M Files M Files 3 Script file so called due to.m filename extension Contains a series of MATLAB commands The

More information

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal COMSC-051 Java Programming Part 1 Part-Time Instructor: Joenil Mistal Chapter 5 5 Controlling the Flow of Your Program Control structures allow a programmer to define how and when certain statements will

More information

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted

More information

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++ CHAPTER 9 C++ 1. WRITE ABOUT THE BINARY OPERATORS USED IN C++? ARITHMETIC OPERATORS: Arithmetic operators perform simple arithmetic operations like addition, subtraction, multiplication, division etc.,

More information

Control Statements Selection (Conditional Logic)

Control Statements Selection (Conditional Logic) Control Statements Selection (Conditional Logic) INTRODUCTION In the last few weeks, you were introduced to the concept of flow of control: the sequence of statements that the computer executes. In procedurally

More information

PHPoC vs PHP > Overview. Overview

PHPoC vs PHP > Overview. Overview PHPoC vs PHP > Overview Overview PHPoC is a programming language that Sollae Systems has developed. All of our PHPoC products have PHPoC interpreter in firmware. PHPoC is based on a wide use script language

More information

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc.

Chapter 1 CONTROL STRUCTURES. SYS-ED/ Computer Education Techniques, Inc. Chapter 1 CONTROL STRUCTURES SYS-ED/ Computer Education Techniques, Inc. ORACLE: PL/SQL: Programming - Advanced Objectives You will learn: Uses and types of control structures. Constructing an IF statement.

More information

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES

DOWNLOAD PDF MICROSOFT EXCEL ALL FORMULAS LIST WITH EXAMPLES Chapter 1 : Examples of commonly used formulas - Office Support A collection of useful Excel formulas for sums and counts, dates and times, text manipularion, conditional formatting, percentages, Excel

More information

Microsoft Excel Level 2

Microsoft Excel Level 2 Microsoft Excel Level 2 Table of Contents Chapter 1 Working with Excel Templates... 5 What is a Template?... 5 I. Opening a Template... 5 II. Using a Template... 5 III. Creating a Template... 6 Chapter

More information

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23.

IECD Institute for Entrepreneurship and Career Development Bharathidasan University, Tiruchirappalli 23. Subject code - CCP01 Chapt Chapter 1 INTRODUCTION TO C 1. A group of software developed for certain purpose are referred as ---- a. Program b. Variable c. Software d. Data 2. Software is classified into

More information

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum: Homepage:

PHPoC. PHPoC vs PHP. Version 1.1. Sollae Systems Co., Ttd. PHPoC Forum:  Homepage: PHPoC PHPoC vs PHP Version 1.1 Sollae Systems Co., Ttd. PHPoC Forum: http://www.phpoc.com Homepage: http://www.eztcp.com Contents 1 Overview...- 3 - Overview...- 3-2 Features of PHPoC (Differences from

More information

IFA/QFN VBA Tutorial Notes prepared by Keith Wong

IFA/QFN VBA Tutorial Notes prepared by Keith Wong Chapter 2: Basic Visual Basic programming 2-1: What is Visual Basic IFA/QFN VBA Tutorial Notes prepared by Keith Wong BASIC is an acronym for Beginner's All-purpose Symbolic Instruction Code. It is a type

More information

BCA-105 C Language What is C? History of C

BCA-105 C Language What is C? History of C C Language What is C? C is a programming language developed at AT & T s Bell Laboratories of USA in 1972. It was designed and written by a man named Dennis Ritchie. C seems so popular is because it is

More information

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0 6 Statements 43 6 Statements The statements of C# do not differ very much from those of other programming languages. In addition to assignments and method calls there are various sorts of selections and

More information

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms

Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras. Lecture - 9 Normal Forms Mathematical Logic Prof. Arindama Singh Department of Mathematics Indian Institute of Technology, Madras Lecture - 9 Normal Forms In the last class we have seen some consequences and some equivalences,

More information

Information Science 1

Information Science 1 Topics covered Information Science 1 Fundamental Programming Constructs (1) Week 11 Terms and concepts from Week 10 Flow of control and conditional statements Selection structures if statement switch statement

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

Control structures: if

Control structures: if Control structures: if Like a recipe tells the cook what to do, a program tells the computer what to do; in imperative languages like Java, lines in the program are imperative statements and you can imagine

More information

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk

Control Statements. Objectives. ELEC 206 Prof. Siripong Potisuk Control Statements ELEC 206 Prof. Siripong Potisuk 1 Objectives Learn how to change the flow of execution of a MATLAB program through some kind of a decision-making process within that program The program

More information

Controlling Macro Flow

Controlling Macro Flow 30 Controlling Macro Flow Control Statement Overview, 30-2 IF, ELSEIF, ELSE,, 30-2 DO,, 30-3 WHILE, ENDWHILE, 30-4 NEXT, 30-5 BREAK, 30-5 GOTO, MLABEL, 30-6 Invoking Macros from Within Macros, 30-7 CALL,

More information

EXCEL WORKSHOP III INTRODUCTION TO MACROS AND VBA PROGRAMMING

EXCEL WORKSHOP III INTRODUCTION TO MACROS AND VBA PROGRAMMING EXCEL WORKSHOP III INTRODUCTION TO MACROS AND VBA PROGRAMMING TABLE OF CONTENTS 1. What is VBA? 2. Safety First! 1. Disabling and Enabling Macros 3. Getting started 1. Enabling the Developer tab 4. Basic

More information

JScript Reference. Contents

JScript Reference. Contents JScript Reference Contents Exploring the JScript Language JScript Example Altium Designer and Borland Delphi Run Time Libraries Server Processes JScript Source Files PRJSCR, JS and DFM files About JScript

More information

Computer Science Lab Exercise 1

Computer Science Lab Exercise 1 1 of 10 Computer Science 127 - Lab Exercise 1 Introduction to Excel User-Defined Functions (pdf) During this lab you will experiment with creating Excel user-defined functions (UDFs). Background We use

More information

Branches, Conditional Statements

Branches, Conditional Statements Branches, Conditional Statements Branches, Conditional Statements A conditional statement lets you execute lines of code if some condition is met. There are 3 general forms in MATLAB: if if/else if/elseif/else

More information

Programming in Python 3

Programming in Python 3 Programming in Python 3 Programming transforms your computer from a home appliance to a power tool Al Sweigart, The invent with Python Blog Programming Introduction Write programs that solve a problem

More information

CPSC 230 Extra review and solutions

CPSC 230 Extra review and solutions Extra review questions: the following questions are meant to provide you with some extra practice so you need to actually try them on your own to get anything out of it. For that reason, solutions won't

More information

CONDITIONAL STATEMENTS AND FLOW CONTROL

CONDITIONAL STATEMENTS AND FLOW CONTROL Contents CONDITIONAL STATEMENTS AND FLOW CONTROL... 1 if Statements... 1 Simple if statement... 1 if/else statement... 3 if/elseif statement... 4 Nested if statements... 5 switch and case... 7 CONDITIONAL

More information