Page 49 - Touchcode_C6_Flipbook
P. 49

4               CONTROL WITH CONDITIONALS












                         Learning Outcomes

                      Introduction                                        Arranging blocks
                      Logical operators                                   Combining logical operators

                      Relational operators                                Nested conditional statements




                 INTRODUCTION
                 In your daily life, you make lot of decisions. Some decisions are small, some are big. Similarly,

                 you also make decisions in programming. In this chapter, you will learn how decision making
                 is done in coding.

                 ARRANGING BLOCKS

                 In the picture given alongside, if you want
                 to build on the given structure, you need
                 to apply a logic. Each time you place a new
                 block,  you  must follow  a rule  to position

                 it so that it forms a diagonal  line  with
                 the blocks marked by arrows. This rule is
                 known as condition in coding.

                 Similarly, in our day-to-day life, we make
                 many decisions depending on our situation.

                 Consider the following life situation:
                    If it is cold outside, then you wear warm
                     clothes, otherwise, you don't.
                    If  it  is  raining  outside,  then  you  need
                     to  carry an  umbrella,  otherwise,  you
                     don't.


                 LOGICAL OPERATORS
                 Logical operators are the fundamental blocks which adds a decision-making capability to
                 code. The three most important logical operators are AND, OR and NOT.





                                                                                     Control with Conditionals   47
   44   45   46   47   48   49   50   51   52   53   54