Chapter3-1d - Chapter3 ProgramControlFlow Sequential (what...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
    Chapter 3 Program Control Flow
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Program Control Flow  Constructs Logical Branching if switch (a good substitute for if under multiple conditions of equality) Iterative (Loops) for (loops) while (loops) Sequential (what we’ve done up to now – only flexibility is different input data.) All programs can be constructed with combinations of the above. No additional constructs are required – in particular goto . When used (some languages still allow, like Fortran) – called spaghetti programming .
Background image of page 2
    Three Forms of the IF Statement if - end if - else – end if – elseif – elseif … [else] – end
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Three Forms of the IF Statement
Background image of page 4
    5 Logical (Relationship) Operators
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    The way we use this type of command typically looks like: if var1 (or exp1) <lop> var2 (or exp2) perform operation end For example: x=1; if x==1 fprintf(‘hey this really works\n’); end A Typical (If Simple) Construct = Assignment Operator == Equality Operator
Background image of page 6
    A Guessing Program (I) In this example the computer will generate a random number from 1 to 10* and then ask the user to guess what the number is. The computer will then notify the user of the result of the guess, and if incorrect, tell the user what the number was. *1, 2, 3, … , 10 (Note use of from and not between)
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    Class Example3_1 % Program guess % Generate a random number between 0 and 1 % Make it a whole number from 1 to 10
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/13/2010 for the course EGR EGR115 taught by Professor Newman during the Spring '10 term at Embry-Riddle FL/AZ.

Page1 / 20

Chapter3-1d - Chapter3 ProgramControlFlow Sequential (what...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online