ME 142 Engineering Computation I. Condition Statements

Size: px
Start display at page:

Download "ME 142 Engineering Computation I. Condition Statements"

Transcription

1 ME 142 Engineering Computation I Condition Statements

2 Key Concepts Relational Operators Logical Operators If-Then-Else Statement GoTo Statement Worksheetfunction.xxx

3 Organization/Name Changes

4 Programming Hints Use nested if statements Use appropriate error checking HW angle of a line HW temperature conversion HW total compensation calculation

5 PP Practice Problem Hints <2:20> (formerly PP 4.1.1)

6 PP Practice Problem Hints <2:21> (formerly PP 4.1.2)

7 PP 5.1.3

8 PP Practice Problem Hints <1:33> (formerly PP 4.1.4)

9 PP 5.1.5

10 HW angle of a line Homework Exercise Hints <2:46> (formerly HW 4.1.1)

11 HW Temperature Conversion Homework Exercise Hints <2:00> (formerly HW 4.1.2)

12 HW 5.1.3

13

14 Relational & Logical Operators

15 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.

16 Relational Operators Common relational operators include: < less than <= less than or equal to > greater than >= greater than or equal to <> not equal to = equal to

17 Logical Operators Logical operators are used in complex expressions to perform a test. Used to check for the validity of multiple conditions being met. Common logical operators include AND, OR, and NOT:

18 Logical Operators 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

19 If-Then-Else Statement

20 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.

21 If-Then-Else Statement Syntax for the If statement is as follows: If condition Then [statements ] [ElseIf condition Then] [statements ] [Else] [statements ] End If

22 If-Then-Else Statement 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.

23 If-Then-Else Statement A one line version of the statement is also available for cases where a single statement is to be executed: If condition Then statement

24 Example Problem Develop a function to give discounts based on the quantity purchased: Less than 25: Greater than/equal to 25: Greater than/equal to 50: Greater than/equal to 75: no discount 10% discount 20% discount 25% discount

25 Example Problem Soln Function Discount(Qty) If Qty >= 25 And Qty < 50 Then Discount = 0.1 ElseIf Qty >= 50 And Qty < 75 Then Discount = 0.2 ElseIf Qty >= 75 Then Discount = 0.25 Else Discount = 0 End If Can you develop an alternative IF statement that will yield the same results? Quantity Discount

26 Select Case

27 Select Case Statement The Select Case structure is useful for decisions that involve three or more options. It is best suited to situations where a block of statements is executed on the basis of the value of a single variable.

28 Select Case Statement Syntax for the Select Case statement is as follows: Select Case condition [Case expressionlist1] [statements ] [Case expressionlist2] [statements ] [Case Else] [statements ] End Select

29 Select Case Example Function Discount(Qty) Select Case Qty Case Is >= 75 Discount = 0.25 Case 50 To 74 Discount = 0.2 Case 25 To 49 Discount = 0.1 Case Else Discount = 0 End Select End Function

30 GoTo Statement

31 GoTo Statement A GoTo statement offers a straightforward means of changing the program flow. GoTo Label This statement transfers program control to a new statement, identified by a label. A label is a text string followed by a colon. ExampleLabel:

32 GoTo Statement In general avoid the use of GoTo Use it only when you have no other way to perform an action. The only time you really need to use a GoTo statement if for error trapping.

33 Example Problem Create a truth table for the following expression: (X <= Y or Y > Z) and X < 3 Use VBA to evaluate the expression above as either True or False, given X = 1, Y=2, and Z=3 (Hint: try using VBA s Immediate Window along with the Print command).

34 Example Problem Soln Create a truth table for the following expression: (X <= Y or Y > Z) and X < 3 X<=Y Y>Z X<3 X<=Y or Y>Z (X <= Y or Y > Z) and X < 3 T T T T T T T F T F T F T T T T F F T F F T T T T F T F T F F F T F F F F F F F

35 Example Problem Soln Use VBA to evaluate the expression above as either True or False, given X = 1, Y=2, and Z=3 (Hint: try using VBA s Immediate Window along with the Print command).

36 Review Questions

37 I-Clicker Question Relational & Logical Operators Given, A=10 and B=8, what does the following expression return: NOT(A>B) A. True B. False C. None of the Above D. Cannot tell from information given

38 I-Clicker Question If-Then-Else Statement Given, perform=3 and sal=100, what does the following function return: A. 0 B. 3 C. 7 D. 100 E. None of the Above Function Bonus(perform, sal) If perform = 1 Then Bonus = sal * 0.1 ElseIf perform = 2 Then Bonus = sal * 0.09 ElseIf perform = 3 Then Bonus = sal * 0.07 Else Bonus = 0 End If End Function

39 Homework Help n Hints

Introductory Notes: Condition Statements

Introductory Notes: Condition Statements 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

More information

APPM 2460: Week Three For, While and If s

APPM 2460: Week Three For, While and If s APPM 2460: Week Three For, While and If s 1 Introduction Today we will learn a little more about programming. This time we will learn how to use for loops, while loops and if statements. 2 The For Loop

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

ME 142 Engineering Computation I. Graphing with Excel

ME 142 Engineering Computation I. Graphing with Excel ME 142 Engineering Computation I Graphing with Excel Common Questions from Unit 1.2 HW 1.2.2 See 1.2.2 Homework Exercise Hints video Use ATAN to find nominal angle in each quadrant Use the AND logical

More information

In this lab, you will learn more about selection statements. You will get familiar to

In this lab, you will learn more about selection statements. You will get familiar to Objective: In this lab, you will learn more about selection statements. You will get familiar to nested if and switch statements. Nested if Statements: When you use if or if...else statement, you can write

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

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

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala Loops and Conditionals HORT 59000 Lecture 11 Instructor: Kranthi Varala Relational Operators These operators compare the value of two expressions and returns a Boolean value. Beware of comparing across

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

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

SELECTION. (Chapter 2)

SELECTION. (Chapter 2) SELECTION (Chapter 2) Selection Very often you will want your programs to make choices among different groups of instructions For example, a program processing requests for airline tickets could have the

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

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

9/9/2017. If ( condition ) { statements ; ;

9/9/2017. If ( condition ) { statements ; ; C has three major decision making instruction, the if statement, the if- statement, & the switch statement. A fourth somewhat less important structure is the one which uses conditional operators In the

More information

Chapter 2: Universal Building Blocks. CS105: Great Insights in Computer Science

Chapter 2: Universal Building Blocks. CS105: Great Insights in Computer Science Chapter 2: Universal Building Blocks CS105: Great Insights in Computer Science Homework 1 It is now available on our website. Answer questions in Word or any text editor and upload it via sakai. No paper

More information

Conditionals and Recursion. Python Part 4

Conditionals and Recursion. Python Part 4 Conditionals and Recursion Python Part 4 Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print (remainder) 1 Boolean expressions An expression that

More information

ME 142 Engineering Computation I. Unit 1.2 Excel Functions

ME 142 Engineering Computation I. Unit 1.2 Excel Functions ME 142 Engineering Computation I Unit 1.2 Excel Functions TOA Make sure to submit TOA If not submitted, will receive score of 0 Common Questions from 1.1 & 1.2 Named Cell PP 1.1.2 Name cell B2 Payrate

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

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

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

Section 13.5: Equations of Lines and Planes. 1 Objectives. 2 Assignments. 3 Lecture Notes

Section 13.5: Equations of Lines and Planes. 1 Objectives. 2 Assignments. 3 Lecture Notes Section 13.5: Equations of Lines and Planes 1 Objectives 1. Find vector, symmetric, or parametric equations for a line in space given two points on the line, given a point on the line and a vector parallel

More information

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan Lecture 08-1 Programming in C++ PART 1 By Assistant Professor Dr. Ali Kattan 1 The Conditional Operator The conditional operator is similar to the if..else statement but has a shorter format. This is useful

More information

Matlab- Command Window Operations, Scalars and Arrays

Matlab- Command Window Operations, Scalars and Arrays 1 ME313 Homework #1 Matlab- Command Window Operations, Scalars and Arrays Last Updated August 17 2012. Assignment: Read and complete the suggested commands. After completing the exercise, copy the contents

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

4. Assignment statements Give an assignment statement that sets the value of a variable called total to 20: Answer: total = 20;

4. Assignment statements Give an assignment statement that sets the value of a variable called total to 20: Answer: total = 20; First Exam Review, Thursday, February 10, 2011 Review all materials from notes, slides, examples and labs. Here is an overview of topics with some example questions in italics. Note: Do not hand in this

More information

Imperative Paradigm. Syntax. Role of Programming Languages. Expressions. Expressions. Role of Programming Languages. Symbols.

Imperative Paradigm. Syntax. Role of Programming Languages. Expressions. Expressions. Role of Programming Languages. Symbols. Imperative Paradigm Syntax Rupesh Nasre. CS3100 Paradigms of Programming IIT Madras Jul 2014 Symbols int, cs12b063, function Expressions 10 * x, abs(x y), ++x Constructs if-else, while {, functionbeginend

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

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

Unit 3. Operators. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION INTRODUCTION Operators Unit 3 In the previous units (unit 1 and 2) you have learned about the basics of computer programming, different data types, constants, keywords and basic structure of a C program.

More information

Announcements. HW0 is posted on schedule, due next Friday at 9pm (pretty easy)

Announcements. HW0 is posted on schedule, due next Friday at 9pm (pretty easy) Branching Announcements HW0 is posted on schedule, due next Friday at 9pm (pretty easy) Office hours (attempt problems before going): - HW only or Lab only (check calendar) - Write name on whiteboard if

More information

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28 Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,

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

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #4 Loops Part II Contents Loop Control Statement

More information

Microsoft Access XP (2002) - Advanced Queries

Microsoft Access XP (2002) - Advanced Queries Microsoft Access XP (2002) - Advanced Queries Group/Summary Operations Change Join Properties Not Equal Query Parameter Queries Working with Text IIF Queries Expression Builder Backing up Tables Action

More information

Syntax of Eiffel: a Brief Overview

Syntax of Eiffel: a Brief Overview Syntax of Eiffel: a Brief Overview EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG Escape Sequences Escape sequences are special characters to be placed in your program text. In Java, an escape sequence

More information

Conditions, logical expressions, and selection. Introduction to control structures

Conditions, logical expressions, and selection. Introduction to control structures Conditions, logical expressions, and selection Introduction to control structures 1 Flow of control In a program, statements execute in a particular order By default, statements are executed sequentially:

More information

Commands, and Queries, and Features. Syntax of Eiffel: a Brief Overview. Escape Sequences. Naming Conventions

Commands, and Queries, and Features. Syntax of Eiffel: a Brief Overview. Escape Sequences. Naming Conventions Commands, and Queries, and Features Syntax of Eiffel: a Brief Overview EECS3311 A: Software Design Fall 2018 CHEN-WEI WANG In a Java class: Attributes: Data Mutators: Methods that change attributes without

More information

Student Outcomes. Classwork. Opening Exercise (3 minutes) Example 1 (8 minutes)

Student Outcomes. Classwork. Opening Exercise (3 minutes) Example 1 (8 minutes) Student Outcomes Students model and write equivalent expressions using the distributive property. They move from a factored form to an expanded form of an expression. Classwork Opening Exercise (3 minutes)

More information

CS 106 Introduction to Computer Science I

CS 106 Introduction to Computer Science I CS 106 Introduction to Computer Science I 06 / 04 / 2015 Instructor: Michael Eckmann Today s Topics Questions / comments? Calling methods (noting parameter(s) and their types, as well as the return type)

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

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

Programming for Experimental Research. Flow Control

Programming for Experimental Research. Flow Control Programming for Experimental Research Flow Control FLOW CONTROL In a simple program, the commands are executed one after the other in the order they are typed. Many situations require more sophisticated

More information

Assignment 6. Methods Homework Spring 2017 P Question 1 all

Assignment 6. Methods Homework Spring 2017 P Question 1 all Assignment 6. Methods Homework Spring 2017 P. 225-234 Question 1 all True since the parameters are different b. True since the parameters are different c. False since the return type is different but the

More information

Errors in Computation

Errors in Computation Theory of Errors Content Errors in computation Absolute Error Relative Error Roundoff Errors Truncation Errors Floating Point Numbers Normalized Floating Point Numbers Roundoff Error in Floating Point

More information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

Chapter 4: Programming with MATLAB

Chapter 4: Programming with MATLAB Chapter 4: Programming with MATLAB Topics Covered: Programming Overview Relational Operators and Logical Variables Logical Operators and Functions Conditional Statements For Loops While Loops Debugging

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

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC 165 H1 Term Test 2 / L5101 Fall 2011 Duration: Aids Allowed: 60 minutes none Student Number: Family Name(s): Given Name(s): Do not turn this page until you have received the signal to start. In the

More information

Flow of Control. 2.1 The if Statement

Flow of Control. 2.1 The if Statement Flow of Control 2 In almost any computer program written for a scientific computing application, we need to allow the computer to execute a collection of statements if and only if some criterion is met.

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

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

Announcements. Homework 0: using cin with 10/3 is NOT the same as (directly)

Announcements. Homework 0: using cin with 10/3 is NOT the same as (directly) Branching Announcements Homework 0: using cin with 10/3 is NOT the same as 3.3333 (directly) With cin, it will stop as soon as it reaches a type that does not match the variable (into which it is storing)

More information

ME 142 Engineering Computation I. Debugging Techniques

ME 142 Engineering Computation I. Debugging Techniques ME 142 Engineering Computation I Debugging Techniques Important Upcoming Events VBA Exam 2 parts In Class Portion Wednesday 11/14 Testing Center Portion 11/12-11/15 Final Project Groups of 3-4 individuals

More information

Control Flow: Branching booleans and selection statements CS GMU

Control Flow: Branching booleans and selection statements CS GMU Control Flow: Branching booleans and selection statements CS 112 @ GMU Topics booleans selection statements: if if-else if-elif(s) if-elif(s)-else flow charts 2 Booleans Booleans - examples Booleans are

More information

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

CSE/NEUBEH 528 Homework 0: Introduction to Matlab CSE/NEUBEH 528 Homework 0: Introduction to Matlab (Practice only: Do not turn in) Okay, let s begin! Open Matlab by double-clicking the Matlab icon (on MS Windows systems) or typing matlab at the prompt

More information

Chapter 2 Homework Vocabulary Inductive reasoning - Conjecture - Counterexample - Conditional - Hypothesis - Conclusion - Truth value - Negation -

Chapter 2 Homework Vocabulary Inductive reasoning - Conjecture - Counterexample - Conditional - Hypothesis - Conclusion - Truth value - Negation - Chapter 2 Homework Vocabulary Inductive reasoning - Conjecture - Counterexample - Conditional - Hypothesis - Conclusion - Truth value - Negation - Converse - Inverse - Contrapositive - Equivalent statements

More information

Quick and simple ClassPad programs for solving problems such as those posed by Project Euler.

Quick and simple ClassPad programs for solving problems such as those posed by Project Euler. Quick and simple ClassPad programs for solving problems such as those posed by Project Euler. Some readers may be familiar with Project Euler (http://projecteuler.net). It is a series of challenging mathematical/computer

More information

Decision Structures CSC1310. Python Programming, 2/e 1

Decision Structures CSC1310. Python Programming, 2/e 1 Decision Structures CSC1310 Python Programming, 2/e 1 Simple Decisions Decision structures, which are statements that allow a program to execute different sequences of instructions for different cases,

More information

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017

Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017 Lecture 3 (02/06, 02/08): Condition Statements Decision, Operations & Information Technologies Robert H. Smith School of Business Spring, 2017 K. Zhang BMGT 404 The modulus operator It works on integers

More information

VBA-Session 6. Conditional Logic. If... Then

VBA-Session 6. Conditional Logic. If... Then VBA-Session 6 Conditional Logic If... Then In logic, a conditional is a statement formed by combining two sentences (or facts) using the words "if... then." It is about saying what has to happen IF a certain

More information

Eric Blasko Dr. Tong Yu CSE-310 digital logic Spring 2018 Homework 3, due 5/14/2018 ( Mon ) 12 pm

Eric Blasko Dr. Tong Yu CSE-310 digital logic Spring 2018 Homework 3, due 5/14/2018 ( Mon ) 12 pm Eric Blasko Dr. Tong Yu CSE310 digital logic Spring 2018 Homework 3, due 5/14/2018 ( Mon ) 12 pm 1. (15 points) Write a Verilog program that simulates the outputs of graycodetobinarycode converter. First

More information

IT 1033: Fundamentals of Programming Loops

IT 1033: Fundamentals of Programming Loops IT 1033: Fundamentals of Programming Loops Budditha Hettige Department of Computer Science Repetitions: Loops A loop is a sequence of instruction s that is continually repeated until a certain condition

More information

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania

CS100: CPADS. Decisions. David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania CS100: CPADS Decisions David Babcock / Don Hake Department of Physical Sciences York College of Pennsylvania James Moscola Decisions Just like a human, programs need to make decisions - Should turtle turn

More information

Lesson 7: If Statement and Comparison Operators

Lesson 7: If Statement and Comparison Operators JavaScript 101 7-1 Lesson 7: If Statement and Comparison Operators OBJECTIVES: In this lesson you will learn about Branching or conditional satements How to use the comparison operators: ==,!=, < ,

More information

This is the basis for the programming concept called a loop statement

This is the basis for the programming concept called a loop statement Chapter 4 Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times did you solve it? What if you had millions of data points

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

Outline for Today CSE 142. Programming a Teller Machine. CSE142 Wi03 I-1. ATM Algorithm for Dispensing Money

Outline for Today CSE 142. Programming a Teller Machine. CSE142 Wi03 I-1. ATM Algorithm for Dispensing Money CSE 142 Outline for Today Iteration repeating operations Iteration in Java while statement Shorthand for definite (counting) iterations for statement Nested loops Iteration Introduction to Loops 1/10/2003

More information

Homework Worksheets: Chapter 7 HW#36: Problems #1-17

Homework Worksheets: Chapter 7 HW#36: Problems #1-17 Homework Worksheets: Chapter 7 HW#36: Problems #1-17 1.) Which of the following in an eample of an undefined term:. ray B. segment C. line D. skew E. angle 3.) Identify a countereample to the given statement.

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

Chapter 4: Control structures. Repetition

Chapter 4: Control structures. Repetition Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

How Do Robots Find Their Way?

How Do Robots Find Their Way? How Do Robots Find Their Way? Conditionals and Repetition http://en.wikipedia.org/wiki/file:cyclope_robot.jpg http://www.youtube.com/watch?v=_l9rklaskwu Learning Objectives Learn basic programming concepts

More information

conditional statements

conditional statements L E S S O N S E T 4 Conditional Statements PU RPOSE PROCE DU RE 1. To work with relational operators 2. To work with conditional statements 3. To learn and use nested if statements 4. To learn and use

More information

Boolean Logic & Branching Lab Conditional Tests

Boolean Logic & Branching Lab Conditional Tests I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists

More information

CMPE 8 Lab 3: Introduction to the Scribbler 2 and SPIN

CMPE 8 Lab 3: Introduction to the Scribbler 2 and SPIN CMPE 8 Lab 3: Introduction to the Scribbler 2 and SPIN Lab Objectives By the end of this lab you should be able to: 1. Identify the key components of the Scribbler 2 robot. 2. Use the Propeller Tool IDE

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

Introduction to Programming for Biology Research

Introduction to Programming for Biology Research Introduction to Programming for Biology Research Introduction to MATLAB: part I MATLAB Basics - The interface - Variables/arrays/matrices - Conditional statements - Loops (for and while) MATLAB: 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

CSE 340 Fall 2014 Project 4

CSE 340 Fall 2014 Project 4 CSE 340 Fall 2014 Project 4 Due on Dec. 5, 2014 by 11:59 pm Abstract The goal of this project is to give you some hands-on experience with implementing a compiler. You will write a compiler for a simple

More information

lab MS Excel 2010 active cell

lab MS Excel 2010 active cell MS Excel is an example of a spreadsheet, a branch of software meant for performing different kinds of calculations, numeric data analysis and presentation, statistical operations and forecasts. The main

More information

Review for Programming Exam and Final May 4-9, Ribbon with icons for commands Quick access toolbar (more at lecture end)

Review for Programming Exam and Final May 4-9, Ribbon with icons for commands Quick access toolbar (more at lecture end) Review for Programming Exam and Final Larry Caretto Mechanical Engineering 209 Computer Programming for Mechanical Engineers May 4-9, 2017 Outline Schedule Excel Basics VBA Editor and programming variables

More information

Chapter 4: Control structures

Chapter 4: Control structures Chapter 4: Control structures Repetition Loop Statements After reading and studying this Section, student should be able to Implement repetition control in a program using while statements. Implement repetition

More information

Math 10C, Lecture 7. Daniel Smith

Math 10C, Lecture 7. Daniel Smith Math 10C, Lecture 7 Daniel Smith 2016-08-17 First things first Write-ups have been graded! Check TritonEd. See me if your function was not excellent. Homework will be like last week. The next part of the

More information

1 Making Decisions in Arduino Programs

1 Making Decisions in Arduino Programs ME 120: If-then-else structures in Arduino October 11, 2018 Gerald Recktenwald gerry@pdx.edu 1 Making Decisions in Arduino Programs It s incredibly useful that computer programs can respond to changing

More information

e.g. D6 contains =bmi($a6,$d$4)

e.g. D6 contains =bmi($a6,$d$4) e) Produce a table which labels columns by heights from 1.55m to 1.95m in steps of 5 cm and rows by weights from 50kg to 95kg in steps of 5kg. At each intersection compute the corresponding body mass index.

More information

Answer Key #1 Phil 414 JL Shaheen Fall 2010

Answer Key #1 Phil 414 JL Shaheen Fall 2010 Answer Key #1 Phil 414 JL Shaheen Fall 2010 1. 1.42(a) B is equivalent to B, and so also to C, where C is a DNF formula equivalent to B. (By Prop 1.5, there is such a C.) Negated DNF meets de Morgan s

More information

EVALUATION COPY. Unauthorized Reproduction or Distribution Prohibited EXCEL ADVANCED

EVALUATION COPY. Unauthorized Reproduction or Distribution Prohibited EXCEL ADVANCED EXCEL ADVANCED Overview OVERVIEW... 2 ADVANCED FORMULAS... 4 VIEW THE PROJECT... 4 Viewing Available Excel Functions... 5 Help with Functions... 6 TEXT FUNCTIONS... 7 Text Functions Used in this Section:...

More information

MTH245 Unit 2 Module1 Piecewise Linear Functions

MTH245 Unit 2 Module1 Piecewise Linear Functions MTH245 Unit 2 Module1 Piecewise Linear Functions A situation with a constant rate of change can be modeled with a linear function: f(x) = mx + b, where b is the initial value and m is the rate of change.

More information

RECURSION, RECURSION, (TREE) RECURSION! 2

RECURSION, RECURSION, (TREE) RECURSION! 2 RECURSION, RECURSION, (TREE) RECURSION! 2 COMPUTER SCIENCE 61A February 5, 2015 A function is recursive if it calls itself. Below is a recursive factorial function. def factorial(n): if n == 0 or n ==

More information

Programming Logic and Design Sixth Edition

Programming Logic and Design Sixth Edition Objectives Programming Logic and Design Sixth Edition Chapter 4 Making Decisions In this chapter, you will learn about: Evaluating Boolean expressions to make comparisons The relational comparison operators

More information

Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

More information

Methods CSC 121 Spring 2017 Howard Rosenthal

Methods CSC 121 Spring 2017 Howard Rosenthal Methods CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Understand what a method is in Java Understand Java s Math Class and how to use it Learn the syntax of method construction Learn both void methods

More information

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 115 Lecture 8. Selection: the if statement. Neil Moore CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

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

Types, Expressions, and States

Types, Expressions, and States 8/27: solved Types, Expressions, and States CS 536: Science of Programming, Fall 2018 A. Why? Expressions represent values in programming languages, relative to a state. Types describe common properties

More information

Computer Programming: C++

Computer Programming: C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming: C++ Experiment #3 Loops Part I Contents Introduction For-Loop

More information

Styles and Conditional Features. Version: 7.3

Styles and Conditional Features. Version: 7.3 Styles and Conditional Features Version: 7.3 Copyright 2015 Intellicus Technologies This document and its content is copyrighted material of Intellicus Technologies. The content may not be copied or derived

More information

Matlab Tutorial: Basics

Matlab Tutorial: Basics Matlab Tutorial: Basics Topics: opening matlab m-files general syntax plotting function files loops GETTING HELP Matlab is a program which allows you to manipulate, analyze and visualize data. MATLAB allows

More information

Mechanical Engineering Department Second Year

Mechanical Engineering Department Second Year Lecture 3: Control Statements if Statement It evaluates a logical expression and executes a group of statements when the expression is true. The optional (elseif) and else keywords provide for the execution

More information

Module 25 Control Flow statements and Boolean Expressions

Module 25 Control Flow statements and Boolean Expressions Module 25 Control Flow statements and Boolean Expressions In this module we learn to generate three address code for control flow statements. We will also try to incorporate short circuit information in

More information