8 if

38 %
62 %
Education

Published on March 9, 2014

Author: fyjordan9

Source: slideshare.net

Basic Scientific Programming Selective Execution

Selective Execution Selective execution gives the programmer the ability to execute a part of the code if a condition is met. Else that part of code is not executed. The selection is based on a logical expression.

Logical Expressions    Logical expressions may be simple or compound. Simple logical expression expression1 logical operator expression2 Compound logical expression formed by combining simple logical expressions by using the following logical operators: NOT, AND, OR, EQV, NEQV.

Relational Operators Symbol Meaning Example < Is less than x<y > Is greater than x>y == Is equal to x == y <= Is less than or equal to x <= y >= Is greater than or equal to x >= y /= Is not equal to x /= y

 The result of a logical operation is either “true” or “false”. 5>4 9<6 3>3 true. false. false.

Characters & Relational Operators   Numeric codes are used to establish an ordering for the character set. ASCII & EBCDIC “Refer to App. A” “CAT” < “DOG” true C precedes D in the table. “June” < “July” false l precedes n in the table. “June” < “june” true J precedes j in the table. Two strings are compared as though blanks are appended to the shorter string. “cat” < “cattle” true a blank space precedes t in the table.

 Logical expressions formed by comparing real values with == are often evaluated as false, why? because real values are stored with some error. Real:: value value = 10 if ( (1/value) == 0.1) then do something end if In this example (1/value) might not result in 0.1 due to storage limitations, it might be 0.998 or 0.10001

Declaring logical variables There are two logical constants in Fortran .TRUE. .FALSE. Declaration: LOGICAL :: VARIABLE_LIST Reading logical variables is similar to reading other data types. Ex. Logical :: A,B,C Read *, A,B,C Input : .T. , F, .False “any form is valid input”

Logical Operators      .NOT. .AND. .OR. .EQV. .NEQV. A F T .NOT. A T F

AND/ OR AND A F B F F T T T OR A .AND. B F A F B F A .OR.B F F F T T F F T F T T T T T T

EQV/NEQV EQV A F B F F T T T NEQV A .EQV. B T A F B A .NEQV. B F F F F T T F F T F T T T T T F

Priorities  In logical expression containing several of these operators, the operations are performed in the following order .NOT.  .AND.  .OR.  .EQV. (or .NEQV.) Parenthesis may be used to indicate the subexpressions that must be evaluated first. Ex: A .AND. B .OR. .NOT. C A .AND. (B .OR. .NOT. C)

The general case The most general case is to have logical expressions containing arithmetic, relational and logical operators. The operations are performed in the following order: 1. Arithmetic operations 2. Relational operations 3. Logical operations Ex: (((b**2 – 4* a* c) >=5) .and. c+2 <6)

Flowchart Symbols Begin or End Input or Output Assignment Point of Selection Multiway Selection Flow Lines join

IF Construct IF (Logical Expression) then Statement-Sequence End IF Selection is made between either executing the sequence of statements or bypassing it. if Stat. seq

General form of IF Construct IF (Logical Expression) then Statement-Sequence1 ELSE Statement-Sequence2 End IF Selection is made between either executing sequence1 or sequence2. if Stat. seq1 Stat. seq2

Nested IF  The sequence of statements in an IF construct may itself contain other IF constructs. Ex: if(X<=0) then value = -X else if (X<1.0)then value = X**2 else value=1.0 end if end if

IF ELSE IF Construct IF(logical expression1) then statement sequence 1 ELSE IF (logical expression2) then statement sequence 2 ELSE IF (logical expression3) then statement sequence 3 . . . ELSE statement sequence n END IF

IF   ELSE IF Construct This structure is used in cases involving multiple alternatives. Only one of the statement sequences will be executed, the others will be skipped.

 User name: Comment:

Related presentations

Management of Mungbean Yellow Mosaic Virus (MYMV) ...

September 21, 2017

How to Write an A+ Research Paper – Guide for St...

September 21, 2017

5 Simple Mistakes That Can Kill Your Essay

September 21, 2017

Anatomy of the Mind Exploring Psychological Mechan...

September 21, 2017

Applied Big Data Analytics in Operations Managemen...

September 21, 2017

Screening of Mungbean Genotypes against Mungbean ...

September 21, 2017

Related pages

In Bearbeitung...

In Bearbeitung ...

Infanteriekarren IF8 – Wikipedia

Das Infanteriefahrzeug If.8 war ein einachsiger militärischer Handkarren oder Anhänger. Die Bezeichnung If.8 stand für den Infanteriekarren. Das If.9 ...

Objektive - Tamron Deutschland - TAMRON - Digital lenses ...

Zentrale: +49 (0) 221 / 970325-0 Service: +49 (0) 221 / 970325-35 Fax: +49 (0) 221 / 970325-4. Wir sind Montag bis Donnerstag von 8:30 bis 17:00 Uhr und ...

Englisch Test zu If-Sätzen Typ 1 und 2

Test zu If-Sätzen mit Bewertung, Schwierigkeit 2

If-Sätze - Typ1, Typ 2 und Typ 3 - Online - Übungen ...

If-Clauses für Klasse 7, Klasse 8, Klasse 9, Klasse 10. Suche; Englisch; Aktiv Passiv; Zeiten; Klasse 5 Englisch; Klasse 6 Englisch; Klasse 7 Englisch;

if-Sätze – Typ I bis III – Aussagesätze – Übung

Übung zu den if-Sätzen Typ 1 bis 3 in Aussagesätzen im Englischen

Übungen - If-Satz Typ 2 - 02 :: 02 - Englisch Lernen mit ...

Übungen - If-Satz Typ 2 - 02 :: Online Englisch Lernen mit kostenlosen Übungen, Erläuterungen, Prüfungsvorbereitung, Spielen, Unterrichtstipps rund um ...

Introduction - Samyang 14mm f/2.8 IF ED UMC Aspherical ...

Samyang 14mm f/2.8 IF ED UMC Aspherical Review ... Review by Klaus Schroiff, published July 2010 Introduction Wide angle enthusiasts just can't get enough ...