Page 128 - Computer Genius Class 08
P. 128

The sequence in which a program's code is executed is known
                  as the  control  ow.   sually, a program s  ow is from top to
                  bottom,  but  what  if we want  a particular  code  to only  be
                  executed when it fulfills a specific condition or wants to run
                  a block of the code a specified number of times? Control  ow
                  statements  are  the statements  that  ensure  a smooth  and

                  intentional  ow of a program. In general, there are three
                  types of statements in Python.
                  These are:

                  l   Sequential statements

                  l   Conditional Statements
                  l   Iterative or looping Statements

                  Sequential Statements


                  As the name implies, these types of statements are executed sequentially, one after another. It is
                  mostly used for simple programs. For example:
                  print("Hi")
                  print ("hello")
                  print ("how are you")

                  Conditional Statements

                  A conditional statement helps to implement decision-making in a program. These statements always
                  result into two outcomes based on specific conditions given by the user. If the condition gets true,

                  the code gives out the first outcome but, if it s false, the second outcome is returned.  ome of the
                  conditional statements are:
                  l   if Statement

                  l   if-else Statement
                  l   if-elif-else Statement

                  if Statement

                  The if statement is the simplest conditional statement.

                  l    Here, the program evaluates the test expression and will execute statement(s) only if the test
                     expression is True. If the test expression is False, the statement(s) is not executed.

                  l    In Python, the body of the ‘if’ statement is indicated by the indentation. Body starts with an
                     indentation and the first unindented statement marks the end.

                  l  Python interprets non-zero values as True.

                  l  None and 0 are interpreted as False.



                      126    Computer Genius-VIII
   123   124   125   126   127   128   129   130   131   132   133