Please enable JavaScript.
Coggle requires JavaScript to display documents.
conditional and looping constructs - Coggle Diagram
conditional and looping constructs
types of statements
statements: they are instructions written in any programming language also called source code given to computer for a specfic task
simple statement
it comprises of a single logical statement also known as single executable statement
compound statement
it comprises of a group of statements they usually execute when a condition is satisfied or a codeblock is directly called through a functional call
here header line starts with a keywords and ends with (:)
empty statement
: it is the simplest statement it serves as a placeholder in python
e.g pass statement which works as a dummy statement it is used in places where it is required syntactically but does not perform any function
programme control and flow
selectional/conditional statements: these statements are executed in a program where a program usses a condition to decide which set of statements are to be executed between two or more set of alternate statements
iterative or looping statements: they are statements in a program that are executed when certain set of statements are to be executed in a loop again and again they contain for and while loop
the condition on which the execution or exit of a loop depends is called test condition
sequential statements: statements in a programme that are executed in an sequential order or linearly without any jump
use of indentation: it refers to leaving white spaces in the code before a statement
leading whitspace (spaces and tabs) python associates the statements at same indentation as a block of code
conditional constructs/statements: the order of flow of statements in a programe is called flow of control
if-else
statement it executes some statements for the true block of statements and some other block of statements if the statement is regarded as false(else block)
if-elif-else
this construct is used in situtations where a user can decide among multiple options if the previous condition were not true then try this one condition ( grading code)
if
statement it simply states that if something is true python should perform steps that follow and do nothing in case of condition being evaluated to be false it is the simplest form of statement
nested
if-elif-statement
it allows the user to check for multiple test expressions and execute different codes for more than 2 conditions
(ek ke andar ek if,else or elif statements)
iteration: the repeation of the a particular statement by using looping statements is called iteration
for loop: it is used to repeat itself over a range of values or a sequence the for loop is executed for each of these items in a range
they are also called definite loops
range() in for loop it is a built in function in python and is used to create a list containing a sequence of numbers n to n-1
while loop: it executes a block of code repeatedly aslong as the test/control condition of the loop is true
using else statements with loops: if else statement is used with a for loop the else statement is executed when the loop has exhausted iterating list
if else statement is used in while loop the else statement is executed when the condition becomes false
infinite loop: if a condition of the loop never becomes false
nested loops: a loop may contain another loop as a part of its body called nested loop once a condition of th outer loop is true the condition is transferred to the inner loop
jump statements: in case of exiting the loop for certain statements or skipping some statements jump statements are used
continue statement: the control jumps to the beginning of the loop for the next iteration and then the normal procedure continues
pass statement: when a statement is required syntactically but you donot want any code or command to execute it is a null operation
break statement: it iterminates the current loop and resumes the execution of the next statement if the break statement is inside a nested loop break will terminate the innermost loop