Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 128 - 2609_Logiccode
P. 128

    IF-ELSE STATEMENT

                                                                                         Start
                      The  if-else  statement  checks  for a condition.  If  the
                      condition evaluates to True, the indented block following
                      the if statement is executed, otherwise the indented block
                      after the else statement is executed.                            if condition

                      Syntax:                                                                                     False
                                                                                            True
                                                                                                         Statements in else
                      if (condition):                                                Statements in if      block execute
                                                                                     block execute
                          Indented block
                      else:
                                                                                         Stop
                          Indented block
                      Program: To compare two numbers and print the result.

                      On running the above program, you will get the following output:

                                NESTED IF STATEMENT

                      A nested if in Python is an if statement placed inside another if statement. This structure allows
                      for more complex decision-making, where a second condition is checked only if the first condition

                      is true.

                      126   Premium Edition-VII

| 123 124 125 126 127 128 129 130 131 132 133 |