Page 127 - ComputerGenius_V2.1_Class8
P. 127

The  sequence  in  which  a  program's  code  is  executed  is  known  as  the  "control  flow."  Usually,  a
                 program's flow 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 flow statements are the statements that ensure a smooth and intentional flow 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
                 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 is true,
                 the code gives out the first outcome but, if it’s false, the second outcome is returned. Some 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.


                                                                                    Control Flow Statements   125
   122   123   124   125   126   127   128   129   130   131   132