SlideShare a Scribd company logo
1 of 15
Civil Engineering
            Skills

      Computer
   Programming

                  CIV1900

             Dr Sam Clarke



    Control of Program Flow
What is Program flow?
Learning outcomes & Aims

◦ What program flow is
◦ Why it may be useful to control the
  flow
◦ How to control program flow using
  sequential logic

           “Making Decisions”
Program Flow

           Process


           Decision



               Data
Program Flow – simple algorithm


                 Data in       A=[1,2;3,4]



             Data processing     A=A*2
                                  B=A



                Data out       B=[2,4;6,8]
Pure logic
Program Flow – another algorithm

            Data in                    A=[1,2;3,4]
                                       if A(1,1)==1
                                         A=A*2
                                       else
          Statement
                                         A=A*3
   True               False            end

Process A             Process B        B=A
                                 1st time B=[2,4;6,8]
          Data out            2nd time B=[6,12;18,24]
                                Decisions give flexibility
Making Decisions– why?
 • When two or more possible
   outcomes are required

 • Decisions are made based on a
   conditional tests

 • if-then

 • if-then-else....
if-then
If this lecture is too boring then I will fall
asleep

if
  expression (this lecture is too boring)
then
  statement (I will fall asleep)

             Let’s code this up
if-then
If this lecture is too boring then I will fall
asleep
                   relational operator
if boredom > tiredness
  student = ‘asleep’
end
                          then is implied
                          by the next line
if-then-else
If I fall asleep in lectures then I will not
understand the lab class otherwise I will
be able to complete the class quickly.
if
  expression (I fall asleep in lectures)
then
  statement (I will not understand the lab)
else
  statement (I will be able to complete the
  class quickly)
if-then-else
If I fall asleep in lectures then I will not
understand the lab class otherwise I will
be able to complete the class quickly.
                  relational operator
if boredom > tiredness
  student = ‘confused in lab’
else
  student = ‘going home early’
end
Relational operators

 Operator    Description

    <        Less than
    <=       Less than or equal to
    >        Greater than
    >=       Greater than or equal to
    ==       Equal to
    ~=       Not equal to
Relational operators
Can be used independently of if-else

     A = 12;
     B = 18;
     C = A > B

Remember = is an assignment
     C = 0
                 False = 0, True = 1
Logical operators
 Operator    Description

    &        True if all relations are
  (AND)      true

    |        True if at least one
  (OR)       relation is true

    ~        True if all relations are
  (NOT)      false
More if-then-else
Conditionals with more than 2 cases can
be built as well:
    if (expression1)
        statement1
    elseif (expression2)
        statement2
    else
        statement3
    end
More if-then-else (Practical 1)
m=randn(100,1);      loops   next week
for loop1=1:100
    if m(loop1)>2
        n(loop1,1)=2;
    elseif m(loop1)<-2
        n(loop1,1)=0;
    else
        n(loop1,1)=1;
    end
end
o=find(n==0);
p=find(n==2);
q=length(o)+length(p);

More Related Content

What's hot

Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityBhavin Darji
 
Numerical analysis multivariable unconstrained
Numerical analysis  multivariable unconstrainedNumerical analysis  multivariable unconstrained
Numerical analysis multivariable unconstrainedSHAMJITH KM
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...Simplilearn
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16Kumar
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programmingcontact2kazi
 
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMS
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMSA NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMS
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMSorajjournal
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programmingAmisha Narsingani
 
Module 4 topic 1 part 3 notes
Module 4 topic 1 part 3 notesModule 4 topic 1 part 3 notes
Module 4 topic 1 part 3 notesAnnie cox
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2Roy Thomas
 
NCC Math 122 Summer Session II Syllabus 2011
NCC Math 122 Summer Session II Syllabus 2011NCC Math 122 Summer Session II Syllabus 2011
NCC Math 122 Summer Session II Syllabus 2011A Jorge Garcia
 
Polymath For Chemical Engineers
Polymath For Chemical EngineersPolymath For Chemical Engineers
Polymath For Chemical EngineersHashim Khan
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programmingJay Nagar
 
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...ijceronline
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design PresentationKawsar Ahmed
 

What's hot (20)

ADA complete notes
ADA complete notesADA complete notes
ADA complete notes
 
Introduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of OptimalityIntroduction to Dynamic Programming, Principle of Optimality
Introduction to Dynamic Programming, Principle of Optimality
 
Numerical analysis multivariable unconstrained
Numerical analysis  multivariable unconstrainedNumerical analysis  multivariable unconstrained
Numerical analysis multivariable unconstrained
 
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
What Is Dynamic Programming? | Dynamic Programming Explained | Programming Fo...
 
04 a ch03_programacion
04 a ch03_programacion04 a ch03_programacion
04 a ch03_programacion
 
Compiler lec 5
Compiler lec 5Compiler lec 5
Compiler lec 5
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
 
Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMS
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMSA NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMS
A NEW ALGORITHM FOR SOLVING FULLY FUZZY BI-LEVEL QUADRATIC PROGRAMMING PROBLEMS
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
Module 4 topic 1 part 3 notes
Module 4 topic 1 part 3 notesModule 4 topic 1 part 3 notes
Module 4 topic 1 part 3 notes
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Dynamic programming 2
Dynamic programming 2Dynamic programming 2
Dynamic programming 2
 
NCC Math 122 Summer Session II Syllabus 2011
NCC Math 122 Summer Session II Syllabus 2011NCC Math 122 Summer Session II Syllabus 2011
NCC Math 122 Summer Session II Syllabus 2011
 
Polymath For Chemical Engineers
Polymath For Chemical EngineersPolymath For Chemical Engineers
Polymath For Chemical Engineers
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...
TYPE-2 FUZZY LINEAR PROGRAMMING PROBLEMS WITH PERFECTLY NORMAL INTERVAL TYPE-...
 
Algorithm Design Presentation
Algorithm Design PresentationAlgorithm Design Presentation
Algorithm Design Presentation
 

Viewers also liked

Viewers also liked (12)

Computer simulations in civil engineering
Computer simulations in civil engineeringComputer simulations in civil engineering
Computer simulations in civil engineering
 
Data representation
 Data representation Data representation
Data representation
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Software And Computer Applications for civil engineering
Software And Computer Applications for civil engineeringSoftware And Computer Applications for civil engineering
Software And Computer Applications for civil engineering
 
Advanced softwares used in civil engineering
Advanced softwares used in civil  engineeringAdvanced softwares used in civil  engineering
Advanced softwares used in civil engineering
 
Inheritance
InheritanceInheritance
Inheritance
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Overloading in java
Overloading in javaOverloading in java
Overloading in java
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 

Similar to Civil Engineering Skills: Control of Program Flow

Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptxrinkugupta37
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 studrohassanie
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manualwebavaq
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptxShimoFcis
 
IRJET- Solving Quadratic Equations using C++ Application Program
IRJET-  	  Solving Quadratic Equations using C++ Application ProgramIRJET-  	  Solving Quadratic Equations using C++ Application Program
IRJET- Solving Quadratic Equations using C++ Application ProgramIRJET Journal
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Nuzhat Memon
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Reviewhassaanciit
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdfishan743441
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
Lesson 1 admin & exponents
Lesson 1 admin & exponentsLesson 1 admin & exponents
Lesson 1 admin & exponentsnjit-ronbrown
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia岳華 杜
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in cyndaravind
 

Similar to Civil Engineering Skills: Control of Program Flow (20)

Python.pptx
Python.pptxPython.pptx
Python.pptx
 
random test
random testrandom test
random test
 
Class_IX_Operators.pptx
Class_IX_Operators.pptxClass_IX_Operators.pptx
Class_IX_Operators.pptx
 
Labsheet2 stud
Labsheet2 studLabsheet2 stud
Labsheet2 stud
 
Daa unit 1
Daa unit 1Daa unit 1
Daa unit 1
 
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions ManualNumerical Methods for Engineers 6th Edition Chapra Solutions Manual
Numerical Methods for Engineers 6th Edition Chapra Solutions Manual
 
lab-8 (1).pptx
lab-8 (1).pptxlab-8 (1).pptx
lab-8 (1).pptx
 
Labsheet2
Labsheet2Labsheet2
Labsheet2
 
Looping
LoopingLooping
Looping
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
IRJET- Solving Quadratic Equations using C++ Application Program
IRJET-  	  Solving Quadratic Equations using C++ Application ProgramIRJET-  	  Solving Quadratic Equations using C++ Application Program
IRJET- Solving Quadratic Equations using C++ Application Program
 
Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)Std 12 Computer Chapter 7 Java Basics (Part 2)
Std 12 Computer Chapter 7 Java Basics (Part 2)
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf2-Algorithms and Complexit data structurey.pdf
2-Algorithms and Complexit data structurey.pdf
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Lesson 1 admin & exponents
Lesson 1 admin & exponentsLesson 1 admin & exponents
Lesson 1 admin & exponents
 
Introduction to julia
Introduction to juliaIntroduction to julia
Introduction to julia
 
Selection & Making Decisions in c
Selection & Making Decisions in cSelection & Making Decisions in c
Selection & Making Decisions in c
 
Intro to matlab
Intro to matlabIntro to matlab
Intro to matlab
 

More from TUOS-Sam

CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlabTUOS-Sam
 
Why computer programming
Why computer programmingWhy computer programming
Why computer programmingTUOS-Sam
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlabTUOS-Sam
 
Orthographic Projections
Orthographic ProjectionsOrthographic Projections
Orthographic ProjectionsTUOS-Sam
 
AutoCAD 2014 Introduction
AutoCAD 2014 IntroductionAutoCAD 2014 Introduction
AutoCAD 2014 IntroductionTUOS-Sam
 
Civil Engineering Skills - Introduction
Civil Engineering Skills - IntroductionCivil Engineering Skills - Introduction
Civil Engineering Skills - IntroductionTUOS-Sam
 

More from TUOS-Sam (7)

CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
Why computer programming
Why computer programmingWhy computer programming
Why computer programming
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 
Orthographic Projections
Orthographic ProjectionsOrthographic Projections
Orthographic Projections
 
AutoCAD 2014 Introduction
AutoCAD 2014 IntroductionAutoCAD 2014 Introduction
AutoCAD 2014 Introduction
 
Civil Engineering Skills - Introduction
Civil Engineering Skills - IntroductionCivil Engineering Skills - Introduction
Civil Engineering Skills - Introduction
 

Civil Engineering Skills: Control of Program Flow

  • 1. Civil Engineering Skills Computer Programming CIV1900 Dr Sam Clarke Control of Program Flow
  • 2. What is Program flow? Learning outcomes & Aims ◦ What program flow is ◦ Why it may be useful to control the flow ◦ How to control program flow using sequential logic “Making Decisions”
  • 3. Program Flow Process Decision Data
  • 4. Program Flow – simple algorithm Data in A=[1,2;3,4] Data processing A=A*2 B=A Data out B=[2,4;6,8] Pure logic
  • 5. Program Flow – another algorithm Data in A=[1,2;3,4] if A(1,1)==1 A=A*2 else Statement A=A*3 True False end Process A Process B B=A 1st time B=[2,4;6,8] Data out 2nd time B=[6,12;18,24] Decisions give flexibility
  • 6. Making Decisions– why? • When two or more possible outcomes are required • Decisions are made based on a conditional tests • if-then • if-then-else....
  • 7. if-then If this lecture is too boring then I will fall asleep if expression (this lecture is too boring) then statement (I will fall asleep) Let’s code this up
  • 8. if-then If this lecture is too boring then I will fall asleep relational operator if boredom > tiredness student = ‘asleep’ end then is implied by the next line
  • 9. if-then-else If I fall asleep in lectures then I will not understand the lab class otherwise I will be able to complete the class quickly. if expression (I fall asleep in lectures) then statement (I will not understand the lab) else statement (I will be able to complete the class quickly)
  • 10. if-then-else If I fall asleep in lectures then I will not understand the lab class otherwise I will be able to complete the class quickly. relational operator if boredom > tiredness student = ‘confused in lab’ else student = ‘going home early’ end
  • 11. Relational operators Operator Description < Less than <= Less than or equal to > Greater than >= Greater than or equal to == Equal to ~= Not equal to
  • 12. Relational operators Can be used independently of if-else A = 12; B = 18; C = A > B Remember = is an assignment C = 0 False = 0, True = 1
  • 13. Logical operators Operator Description & True if all relations are (AND) true | True if at least one (OR) relation is true ~ True if all relations are (NOT) false
  • 14. More if-then-else Conditionals with more than 2 cases can be built as well: if (expression1) statement1 elseif (expression2) statement2 else statement3 end
  • 15. More if-then-else (Practical 1) m=randn(100,1); loops next week for loop1=1:100 if m(loop1)>2 n(loop1,1)=2; elseif m(loop1)<-2 n(loop1,1)=0; else n(loop1,1)=1; end end o=find(n==0); p=find(n==2); q=length(o)+length(p);