{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter3-1d

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

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

Chapter 3 Program Control Flow

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

View Full Document
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 .
Three Forms of the IF Statement if - end if - else – end if – elseif – elseif … [else] – end

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

View Full Document
Three Forms of the IF Statement
5 Logical (Relationship) Operators

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

View Full Document
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
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)

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

View Full Document
Class Example3_1 % Program guess % Generate a random number between 0 and 1 % Make it a whole number from 1 to 10 % Ask the user to guess the number
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online