Introduction to Programming for Mechanical Engineers (ME 319)

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

CS 101 Introductory Programming - Lecture 7: Loops In C & Good Coding Practices Presenter: Ankur Chattopadhyay.
Fundamental of C programming
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Decision Making EE2372 Software Design I Dr. Gerardo Rosiles.
Making Decisions in Python Sec 9-10 Web Design. Objectives The student will: Understand how to make a decision in Python Understand the structure of an.
Conditional Statements Introduction to Computing Science and Programming I.
1 Lecture 8:Control Structures I (Selection) (cont.) Introduction to Computer Science Spring 2006.
true (any other value but zero) false (zero) expression Statement 2
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Tutorial 4 Decision Making with Control Structures and Statements Section A - Decision Making JavaScript Tutorial 4 -Decision Making with Control.
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
Programming Fundamentals. Today’s lecture Decisions If else …… Switch Conditional Operators Logical Operators.
ENG 1181 College of Engineering Engineering Education Innovation Center MAT – Conditional Statements Topics: 1.Conditional statements if-end if-else-end.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
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.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Introduction to branching.
Introduction to Engineering MATLAB - 13 Agenda Conditional statements  If – end  If – else – end  if – elseif – else - end.
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
IT CS 200: C ONDITION Lect. Napat Amphaiphan. T HE ABILITY TO CONTROL THE FLOW OF YOUR PROGRAM, LETTING IT MAKE DECISIONS ON WHAT CODE TO EXECUTE 2.
Conditional Logic in MATLAB By Bruce Raine. How to do a basic IF – END structure in MATLAB if MATLAB Commands end i.e. do the MATLAB commands if the conditional.
1 CS428 Web Engineering Lecture 13 Flow Control & Loops (JavaScript - III)
CHAPTER 3 CONTROL STRUCTURES ( SELECTION ) I NTRODUCTION T O C OMPUTER P ROGRAMMING (CSC425)
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
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.
 Very often when you write code, you want to perform different actions for different decisions. You can use conditional statements in your code to do.
If/Else Statements.
ITEC 2600 Introduction to Analytical Programming
CNG 140 C Programming (Lecture set 3)
Conditional or Decision Logic
Introduction to Programming for Mechanical Engineers (ME 319)
Introduction to Programming for Mechanical Engineers (ME 319)
Sequence, Selection, Iteration The IF Statement
Introduction to C++ Programming Language
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
OF COURSE I DON'T LOOK BUSY... I DID IT RIGHT THE FIRST TIME
Chapter 4 MATLAB Programming
Operator Precedence Operators Precedence Parentheses () unary
Introduction to Programming for Mechanical Engineers
Programming Fundamentals
Control Structures.
Selection By Ramin && Taimoor
ICS 3U Tuesday, September 21st.
IF if (condition) { Process… }
Conditional Statements
محاضرة 1: مقدمة للمسـاق و مراجعـة للأساسيـات
During the last lecture we had a discussion on Data Types, Variables & Operators
Logical Operations In Matlab.
Selection Statements.
Conditional Statements
Conditional Logic Presentation Name Course Name
SELECTIONS STATEMENTS
Lecture Notes – Week 2 Lecture-2
PROGRAM FLOWCHART Selection Statements.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Selection—Making Decisions
Control Statements.
Chapter 3: Selection Structures: Making Decisions
Selection Control Structure
PHP CONDITIONAL STATEMENTS
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
ME 123 Computer Applications I Lecture 11: More on For loop 3/27/03
Presentation transcript:

Introduction to Programming for Mechanical Engineers (ME 319) Lecture 6.2

Things you should have known so far! If you didn’t have it before, you should have developed some knowledge of logic design. True-False or 0-1 representation Understand the nature of logical and relational operators. Clearly forming logical and relational operators to represent the case(s) you may have. Correctly arrange combined conditions to represent more complex case(s).

Conditional Statements: if-end Conditional statements are statements designed to allow MATLAB to make decision making. Here, the MATLAB may execute a group of commands or skip them based on the satisfaction of a condition(s). Syntax: if conditional expression(s), logical and relational body of ‘if’ statement end START IF STATEMENT FALSE TRUE Group of commands Example: if n_boys>=0 n_students = n_girls + n_boys; end END

Conditional Statements: if-else-end If-else-end is a two way conditional statement. The statement checks the satisfaction of the condition. If it is satisfied, it chooses command group 1 and executes it. If the condition is false, it chooses group 2 and executes it. START IF STATEMENT FALSE TRUE Example: if GPA>=3.0 DECISION = ‘PASS' else DECISION = ‘FAIL' end Group of commands 2 Group of commands 1 END

Conditional Statements: if-elseif-end If-elseif-end is a multi way conditional statement. The statement checks the satisfaction of the first condition. If it is satisfied, it chooses commands group 1 and executes it. If the condition is false, it goes to the second else-if statement. It performs the same check to choose group 2 or 3. START IF STATEMENT FALSE Example: if GPA>=3.75 EVALUATION = ‘A' elseif GPA<3.75 & GPA>=3.50 EVALUATION = ‘B+' else % GPA<3.50 & GPA>=3.20 EVALUATION = ‘B‘ end ELSE-IF STATEMENT TRUE FALSE Group of commands 1 TRUE Group of commands 3 Group of commands 2 END

.. Conditional Statements: switch-case-otherwise-end switch-case-otherwise-end is a conditional statement that works in parallel. Only one case is selected and the commands that follow it will be executed. START switch .. otherwise case value 3 case value 2 case value 1 END

Conditional Statements: switch-case-otherwise-end passengers = input('Enter number of passengers '); passengers = ceil(passengers); switch passengers case 1 Car_type = 'Coupe' Rate_per_day_USD = 27 case 2 case 3 Car_type = 'Economy' Rate_per_day_USD = 22 case 4 Car_type = 'Sedan' Rate_per_day_USD = 25 case 5 Car_type = 'Full Size' Rate_per_day_USD = 40 case 6 Car_type = 'Minivan' Rate_per_day_USD = 57 otherwise fprintf('We do not hold cars that fit this number of passengers\n\n') end Enter number of passengers 5 Car_type = Full Size Rate_per_day_USD = 40.00

Thank you for the attention Any Questions and Suggestions please…