If-Else Statements Flashcards
Use nested if-else statements, elseif, when an input can lead to several different outcomes. This is more efficient that executing every command. If-else statements allow program to skip unnecessary actions.
Use x >= -1 && x
Switch statements are used when an expression is equal to one of several possible values.
Use curly braces to combine expression values: switch x case {4, 5} disp('x is four or five') end
switch switch_expression case ex1 action1 case ex2 action2 ... otherwise action end
Menu function uses a list of strings to create a choice of buttons equivalent to the number of the button.
Other functions include:
isequal(x)
isletter(x) - determine if a variable is a letter
isempty(x) - determine if a variable has a value
iskeyword(‘string’) - determine if string is a MATLAB keyword
iskeyword - returns a list of MATLAB keywords
If statements operate using logical true or false conditions and only evaluate if condition is true.
Remember, any nonzero number means true. Only 0 will return false.