Page 47 - CloudGPT_C7_Flipbook
P. 47

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. Every time when  you

                 place a new block, you need to apply the
                 logic for placing the block in such a way
                 that it will build a diagonal line with blocks
                 marked with arrows. This logic is known as

                 conditions 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   45
   42   43   44   45   46   47   48   49   50   51   52