Page 78 - iPrime_V2.2_class6
P. 78

b.   If the mangoes are not there, you will make cold coffee.

                     Here the condition is the availability of mango.
                     We can also write this in two ways:
                     1. if                                               2. if
                            mango is available                               mango is available
                       then                                               then
                            make the mango shake                             make the mango shake
                                                                          else
                                                                             make cold coffee

                       In such situations, we use conditional blocks. Scratch has two conditional blocks. They are:
                  1.   If...then block: In this block if the condition is true, the blocks inside then or only inside
                     conditional block will run. If the condition is false, the blocks inside conditional block will not
                     run. Only the blocks outside the conditional block will run.

                  2.   If...then...else block: In this block if the condition is true, the blocks inside then condition will
                     run. If the condition is false, the blocks inside else condition will run.
                     Try out the following examples:

                     Suppose, we want to check whether a person is a senior citizen or not. The code for this can
                    be defined using if...then as:
















                     But this code does not give an output if the age of the person is less than or equal to 60 years.
                    For such situations, when two different outputs are to be specified for two conditions, we
                    use the if…then…else block. In this block, if the condition is true, the code inside the first C
                    (shape) will be activated. If the condition is false, the code inside the second C (shape) will be
                    activated.






















                  76     iPRIME (Ver. 2.2)–VI
   73   74   75   76   77   78   79   80   81   82   83