If-Else Statements Flashcards

1
Q

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.

A

Use x >= -1 && x

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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
A
switch switch_expression
   case ex1
      action1
   case ex2
      action2
   ...
   otherwise
      action
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Menu function uses a list of strings to create a choice of buttons equivalent to the number of the button.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If statements operate using logical true or false conditions and only evaluate if condition is true.

A

Remember, any nonzero number means true. Only 0 will return false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly