Page 77 - 2502_Pakistan-kifayat_C-8
P. 77

IF-THEN-ELSE Statement

                 The IF-THEN-ELSE conditional statement checks a condition and does one thing if it's true, another if
                 it's false.

                 The syntax of the IF-THEN-ELSE statement is as follows:
                                                                                   Start
                 If Test expression Then

                     Body of if

                 Else
                                                                                   Test        False      Body of else
                     Body of else                                               Expression
                 For example, to determine whether marks obtained are
                 40 or more, otherwise, the result is Fail.
                                                                                      True
                 Start
                                                                                 Body of if
                 Input number marks
                 IF marks > 40 Then

                    Print "Pass"
                                                                                   Stop
                 Else

                     Print "Fail"
                 End
                 The pseudocode checks if the marks obtained are greater than or equal to 40. If this condition is true,
                 it displays Pass; otherwise, it displays Fail". This is done using an IF-THEN-ELSE conditional statement to
                 make the decision based on the given marks.

                 Using Multiple Conditions

                 Sometimes, a decision depends on more than one condition. In such cases, we use logical operators like
                 AND, OR, and NOT to combine multiple conditions in a single IF statement. We need logical operators
                 when we want to check more than one condition at the same time in a program. They help us combine
                 multiple conditions and make smarter decisions.

                 For example: The pseudocode sets age to 14 and score to 60. It checks if age is greater than 12 and
                 score is greater than 80. Since only the age condition is true, the message "Eligible for Scholarship" is
                 not displayed.

                 Start
                 Set age = 14

                 Set score = 60
                 IF age > 12 AND score > 80 Then
                     Print "Eligible for Scholarship"

                 End








                                                                                                          #Nesting  75
   72   73   74   75   76   77   78   79   80   81   82