Fortran 2- More Basics Chapter 3 in your Fortran book.

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

Chapter 4: Control Structures I (Selection)
Chapter 2 Flow of Control. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Learning Objectives Boolean Expressions Building, Evaluating.
LIS651 lecture 3 numbers, Boolean, control flow Thomas Krichel
C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 4: Control Structures I (Selection)
Chapter 13 Control Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display Control Structures Conditional.
The "if structure" is used to execute statement(s) only if the given condition is satisfied.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program.
CS0007: Introduction to Computer Programming
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Conditional Statements Introduction to Computing Science and Programming I.
Overview Program flow Decision / branching / selection structures True & False in Python Comparison operators & Boolean expressions if … if … else if …
Decisions (Conditional Programming) Chapter 5 (Sec. 5.1 & 5.2)
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
1 Lecture 7:Control Structures I (Selection) Introduction to Computer Science Spring 2006.
Flow control 1: if-statements (Liang 72-80) if(radius < 0) { System.out.println(“cannot get area: radius below zero”); } else { double area = radius *
CSCI 130 Chapter 4 Statements, Expressions, and Operators.
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Control Structures – Selection Chapter 4 2 Chapter Topics  Control Structures  Relational Operators  Logical (Boolean) Operators  Logical Expressions.
Logical Operators Jumps Logical Operators The different logical operators found in Java Rational Operators The different rational operators found in Java.
PAGES:51-59 SECTION: CONTROL1 : DECISIONS Decisions.
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Four Fundamental Pieces Instruction Control Structure Function Expression.
ITM 352 Flow-Control: if and switch. ITM © Port, KazmanFlow-Control - 2 What is "Flow of Control"? Flow of Control is the execution order of instructions.
1 Boolean Expressions to Make Comparisons Boolean expression –Represents only one of two states –Expression evaluates to either true or false Expressions.
Chapter 3. Outline Relational Operators Loops Decisions Logical Operators Precedence Summary.
If…else statements. Boolean Expressions Boolean expression - An expression whose value is either true or false true = 1 false = 0 Datatype: boolean.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
Conditional Statement Chapter 8. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement.
Operators Precedence - Operators with the highest precedence will be executed first. Page 54 of the book and Appendix B list C's operator precedence. Parenthesis.
Programming 1 DCT 1033 Control Structures I (Selection) if selection statement If..else double selection statement Switch multiple selection statement.
Conditional Expression One of the most useful tools for processing information in an event procedure is a conditional expression. A conditional expression.
Copyright © 2012 Pearson Education, Inc. Chapter 4: Making Decisions.
Activity 2 Practice.
Flow of Control Unless indicated otherwise, the order of statement execution through a method is linear: one after the other in the order they are written.
Basic Conditions. Challenge: ● Ask the user his/her name ● If it’s “Wally,” jeer him ● Pause video and try on your own.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
USING CONDITIONAL CODE AMIR KHANZADA. Conditional Statement  Conditional statements are the set of commands used to perform different actions based on.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Control Structures (Selection & Repetition)
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
ME 142 Engineering Computation I Condition Statements.
C++ for Engineers and Scientists Second Edition Chapter 4 Selection Structures.
 Type Called bool  Bool has only two possible values: True and False.
Chapter 2 Section 2 Absolute Value
Introduction to Programming for Mechanical Engineers (ME 319)
Sequence, Selection, Iteration The IF Statement
Chapter 4: Making Decisions.
Introduction to C++ Programming Language
EGR 2261 Unit 4 Control Structures I: Selection
Operator Precedence Operators Precedence Parentheses () unary
ITM 352 Flow-Control: if and switch
Expressions and Control Flow in JavaScript
Control Structures.
Control Structures – Selection
Conditional Statements
Computers & Programming Languages
Bools and simple if statements
Types, Truth, and Expressions (Part 2)
Relational Operators Operator Meaning < Less than > Greater than
Pages:51-59 Section: Control1 : decisions
Logical Operations In Matlab.
Selection Statements.
Conditional Statements
Conditional Logic Presentation Name Course Name
Chapter 3: Selection Structures: Making Decisions
Boolean Expressions to Make Comparisons
Relational Operators.
Chapter 5 Decisions.
Chapter 4: Boolean Expressions, Making Decisions, and Disk Input and Output Prof. Salim Arfaoui.
Pages:51-59 Section: Control1 : decisions
Presentation transcript:

Fortran 2- More Basics Chapter 3 in your Fortran book

Logical IF Structures We dealt very briefly in Excel with if statements that are used to carry out specific actions based on certain logical conditions. There are a number of situations in Fortran programming when logical comparisons are valuable in determining the actions that the program will take. To make a logical comparison we will require the following operators: OPERATORMEANING.EQ.equal to.NE.not equal to.LT.less than.LE.less than or equal to.GT.greater than.GE.greater than or equal to In order to use these operators we make a comparison such as (AREA.LT.0) that translates to “AREA less than zero”. This is a logical expression which can be used in an IF statement. A program may make use of a simple logical IF statement, or a block IF statement.

Logical Operators Logical expressions can be combined using logical operators: –.OR. and.AND. ex: IF(X.GT.10.AND.X.LT.25) The logical expression can be changed to the opposite value by preceding it with.NOT. ex:.NOT.(A.LT.15) The order of priority, from highest to lowest is:.NOT.,.AND.,.OR.

One line IF Statement Making use of a logical IF statement which may be expressed on a single line takes the following form: IF (logical expression) executable statement For example: IF (STRESS.GT.FY) STRESS=FY

Block IF Statements In many cases the conditions require more than a simple executable statement. In these situations we will use a “block IF statement”. If(logical expression) Then statement 1. statement n END IF If the logical statement is true, the statements within the Block If will be executed. If the logical statement is false, the program will jump to the END IF statement and none of the statements within the BLOCK IF will be executed.

Else There are other statements associated with the BLOCK IF structure such as the ELSE and ELSE IF statements: If(logical expression 1) THEN statement 1. statement m ELSE statement m+1. statement n END IF The above command will evaluate the logical expression, and if true will execute statements 1 through m. If the logical expression is false (ELSE) statements m+1 through statements n will be carried out.

Else IF If(logical expression 1) THEN statement 1. statement m ELSE IF (logical expression 2) THEN statement m+1. statement n ELSE statement n+1. statement o END IF This will first evaluate the logical expression 1, and if true will execute statements 1 through m and then skip to the END IF. If logical expression 1 is false (ELSE IF), logical expression 2 will be evaluated, and if true statements m+1 through n will be executed and then the program will skip to the END IF. If the both logical expressions 1 and 2 are false (ELSE) statements n+1 through statement o will be carried out and the IF BLOCK will terminate at the END IF statement. We can string together several IF, ELSEIF statements to satisfy the conditions of our problem. The BLOCK IF structure can sometimes be confusing to follow so it is highly encouraged to indent individual sections of the BLOCK IF to set the different sections apart.

Example Write a simple Fortran program to evaluate the stress in the rod for a given load, area, and yield stress (F y )