Page 153 - The Ultimate Palm Robot
P. 153

Color profile: Generic CMYK printer profile
           Composite  Default screen
                                                      Bots / The Ultimate Palm Robot/ Mukhar & Johnson / 222880-6 / Chapter 6






                    136     The Ultimate Palm Robot



                                 Want an example? If you have a variable (let’s call it x), you can test it for
                               various conditions. The program might need to make a decision based on cri-
                               teria: if x is greater than some value (x > 5), less than some value (x < 10), or
                               equal to some value (x == 13), for instance. Using the and or or operators, you
                               can further test for multiple conditions. For example, you can test if x lies be-
                               tween two values (the condition x>5&&x<10 is read as “x greater than 5 and
                               x less than 10.” It is true if x is between 5 and 10); or whether x meets any one
                               of several conditions (the condition x==2||x==4 is read as “x equals 2 or x
                               equals 4” and means the condition is true if either x equals 2 or x equals 4).

                                 In addition to the If component, the Else component is used when you want
                               some code to execute when the condition is false. The Else block must be
                               added somewhere between the If and EndIf blocks. When you add an Else
                               block, the PRP automatically adds an EndElse block. Every program compo-
                               nent between Else and EndElse will be executed if the condition property of
                               the If block is false.















                               NOTE:    The PRP will not stop you from adding an Else block anywhere
                               within a program. However, if you place an Else block where it is not between
                               an If and End If block, your program will not work.
                               The While Component    A While component allows you to perform a loop
                               until some condition is met. The single property for the While component is
                               the condition. This condition meets the same parameters as the condition for
                               the If component. When you add a While block to your program, the PRP
                               automatically adds an EndWhile block. You can add components between the
                               While and EndWhile blocks. When the While component is encountered, the
                               condition is tested. If the condition is true, the components between the While
                               and EndWhile blocks are executed. The program then goes back to the start of
                               the While component. If the condition is false, the program goes to the next
                               component after the EndWhile component; if true, it executes the
                               components contained in the While component again.







           P:\010Comp\Bots\880-6\ch06.vp
           Monday, May 12, 2003 1:06:23 PM
   148   149   150   151   152   153   154   155   156   157   158