Control and Loop Statements in Python PYTHON by Ravinder Nath Rajotiya - April 19, 2019May 10, 20210 Control Statements There are many instances when it is required to take decision. If statement is a decision making statement. If statement in Python is used to test a condition and transfer the control of program to usual sequential next line of code or skips certain lines and jump to another point. It should be clearly noted that Python make use of indentation almost every where especially while writing if statement. If indentation is not used in a statement that particular line of code will be treated as not part of if statement or loop statements and is thus treated as statement outside the control and loop. example: >>> x=10 >>> if x>0: . . . print(x," is +ve Number") #indented line thus executed
FOR Loop PYTHON by Ravinder Nath Rajotiya - April 19, 2019May 10, 20210 For Loop is used to iterate a task number of times. The loop allows traversal over an iterable objects like lists, tuple and strings. Syntax: >>> for val in sequence : . . . body of for >>> else: . . . body of else part here val is a variable that takes values from the sequence. On each iteration val takes one value from the sequence of iterable object till all items are exhausted. Flowchart of a Loop Process in Python