MATLAB for the Sciences

Conditional Control Loop Control References MATLAB for the Sciences Control Structures Jon M. Ernstberger January 8, 2008 Jon M. Ernstberger MATLA...
Author: Allen Griffin
29 downloads 3 Views 153KB Size
Conditional Control Loop Control References

MATLAB for the Sciences Control Structures Jon M. Ernstberger

January 8, 2008

Jon M. Ernstberger

MATLAB for the Sciences

Conditional Control Loop Control References

The purpose of conditional control Some executions require a decision! Example: driving. You approach an intersection with a traffic light. You: a.) Stop if the light is red. b.) Go if the light is green.

Example: Monopoly. You roll the dice and have the following options: a.) Both dice have different numbers. You just go forward that number of spaces. b.) You roll doubles. You go forward that number AND get to roll again. c.) You roll doubles 3 times consecutively. You go to jail.

Jon M. Ernstberger

MATLAB for the Sciences

Conditional Control Loop Control References

The IF Statement One of the big ones! Usage if LOGICAL STATEMENT IS TRUE . statement . end; If the logical statement is true, then the code inside the “if”-statement is executed. Example if 25 & x