An interactive introduction to MATLAB

(Jeff_L) #1

52 decision making


Self Test Exercise: The if-else statement
Evaluate the following expressions without usingMATLAB.


  1. Which of the following shows a correctif,elsestatement?
    a).
    1 a = input('a? ')
    2 If a < 0
    3 disp('a is negative')
    4 ELSEIF a == 0
    5 disp('a is equal to zero')
    6 Else
    7 disp('a is positive')
    8 END


b).
1 a = input('a? ')
2 if a < 0
3 disp('a is negative')
4 elseif a = 0
5 disp('a is equal to zero')
6 else
7 disp('a is positive')
8 end

c).
1 a = input('a? ')
2 if a < 0
3 disp('a is negative')
4 elseif a == 0
5 disp('a is equal to zero')
6 else
7 disp('a is positive')
8 end

d).
1 a = input('a? ')
2 if a < 0
3 disp('a is negative')
4 else if a = 0
5 disp('a is equal to zero')
6 else
7 disp('a is positive')
8 end
Free download pdf