Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 119 - 2610_Springdales_C-7
P. 119

    Now answer the following in binary digits:

                           1.  Write all the prime numbers between 1 and 10.

                           2.  Write all the even numbers between 1 and 10.

                           3.  Write the sum of 5 and 4.

                           4.  Write all the numbers divisible by 3 between 1 and 10.

                     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 a condition will always be either True or False.

                     if-then-else                                                            Start

                     The program executes the  statements
                     written inside the IF block when  the                                IF (Condition)
                     condition is True. If the condition is False,       True            to be checked            False
                     the  statements written  inside  the  else
                     block will be executed. A block refers to a    Statements inside IF              Statements inside ELSE
                                                                     block will execute
                     section of code that is grouped together.                                           block will execute

                     Look at these examples:                                                 Stop

                      Example 1:                                               Example 2:

                      READ Subject                                             READ marks
                      IF Subject = "Maths" THEN                                IF marks > 50 THEN
                         PRINT "Take out Maths book & notebook"                   PRINT "Pass"
                      ELSE                                                     ELSE
                         PRINT "Check timetable"                                  PRINT "Fail"

                      Example 3:                                               Example 4:
                      READ Rain                                                READ age
                      IF Rain = True THEN                                      IF age >= 18 THEN
                         PRINT "Carry an umbrella"                                PRINT “You are eligible to vote.”

                      ELSE                                                     ELSE
                         PRINT "Do not carry an umbrella"                         PRINT “You are not eligible to vote.”

                                                                                              Algorithmic Intelligence  117

| 114 115 116 117 118 119 120 121 122 123 124 |