Page 83 - TP-Play_V-2.0_Book-7
P. 83

ALGORITHMIC INTELLIGENCE





                CONDITIONS IN A PROGRAM

            While writing a program, we need to make certain decisions based on the logic of the

            program.  Such situations are called conditions. Conditional statements are used in
            a program to instruct the computer to make a decision. The result of the computer’s
            decision for a condition will always be either a true or a false.
            if-then-else


            The program executes the statements written after ‘if’ when the condition is true. If it is
            false, the statements written after ‘else’ will be executed.
                                                                                                                         Computational Thinking

                                          Yes           If (Condition)          No
                                                        to be checked
                                         Then                                   Else

                             Do this                                                    Do that

            Look at these examples:
                     Example 1:                                        Example 2:


                     If                                                Read marks
                         It is Maths class                             If marks is > 50
                     Then                                                  Display Pass
                         Take out Maths book & notebook                Else
                                                                           Display Fail

                     Example 3:                                        Example 4:

                     If                                                If
                         It is raining                                     Number is divisible by 2
                     Then                                              Then
                         Carry an umbrella                                 Print “The number is EVEN”
                     Else                                              Else

                         Do not carry an umbrella                          Print “The number is ODD”







                                                               The CT Corner! (Algorithmic Intelligence)     83
   78   79   80   81   82   83   84   85   86   87   88