a character :e e is a vowel Output : Enter a character :x x the letter is not a/b/c Example .5a: #Program to illustrate the use of ‘in’ and ‘not in’ in if statement . . . Iteration or Looping constructs Iteration or loop are used in situation when the user need to execute a block of code several of times or till the condition is satisfied.
A loop statement allows to execute a statement or group of statements multiple times. Condition Statement Statement ... Statement n Further Statements of Program else Statement Statement ... Statement n False True Fig .
Diagram to illustrate how looping construct gets executed Python provides two types of looping constructs: • while loop • for loop 12th Computer Chapter - - Control Structures (i) while loop The syntax of while loop in Python has the following syntax: Syntax: while <condition>: statements block [else: statements block2] Condition Conditional Code while Expression: Statement (s) if conditions is true if condition is false Fig . while loop execution In the while loop, the condition is any valid Boolean expression returning True or False. The else part of while is optional part of while . The statements block1 is kept executed till the condition is True.
If the else part is written, it is executed when the condition is tested False. Recall while loop belongs to entry check loop type, that is it is not executed even once if the condition is tested False in the beginning. i= # intializing part of the control variable while (i<= ): # test condition print (i,end='\t') # statements - block i=i+ # Updation of the control variable Output: Example . : program to illustrate the use of while loop - to print all numbers from to 12th Computer Chapter - - In the above example, the control variable is i , which is initialized to .
Next the condition i<= is tested , if the value is true i gets printed, then the