Page 24 -
P. 24

elseif expression 2
                                     Commands 2 evaluated if expression 2 is True
                                   elseif expression 3
                                     Commands 3 evaluated if expression 3 is True
                                   …
                                   else
                                     Commands evaluated if no other expression is True
                                   end

                             In this form, only the commands associated with the first True expression
                             encountered are evaluated; ensuing relational expressions are not tested.


                             1.5.2.1  Alternative Syntax to the if Statement
                             As an alternative to the if syntax, we can use, in certain instances, Boolean
                             expressions to specify an expression in different domains. For example,
                             (x>=l) has the value 1 if x is larger than or equal to 1 and zero otherwise;
                             and (x<=h) is equal to 1 when x is smaller than or equal to h, and zero oth-
                             erwise.
                              The relational operations allowed inside the parentheses are: ==, <=, >=,
                             ~=, <, >.



                             Homework Problem

                             Pb. 1.2 For the values of integer a going from 1 to 10, using separately the
                             methods of the if syntax and the Boolean alternative expressions, find the
                             values of C if:

                                                    C =  a 2  for  a < 3
                                                       a
                                                    C =+ 5    for  3 ≤  a < 7
                                                    C =  a    for  a ≥ 7

                             Use the stem command to graphically show C.








                             1.6  Array Operations

                             In the above examples, we used for loops repeatedly. However, this kind of
                             loop-programming is very inefficient and must be avoided as much as possi-


                             © 2001 by CRC Press LLC
   19   20   21   22   23   24   25   26   27   28   29