Introduction of control structure and Simple control statements

control structure in c decide how the flow of  control in a program

control structure includes logical statements like if-else and switch statements and also include the loops to do work repetitively i.e for, while, and, do-while loop.


if statements:


if statement is used when we want to execute some lines of code with some conditions.


syntax:


if(condition){


    statements to be executed  when the condition is true


}




if-else statements: 


if we want that your code runs only if a particular condition is true then we use if statement and with if we want that when that particular condition becomes false we want to execute some other code then we use else statement.


Remember that else statement always comes with if statement, but it is not compulsory to use else statement with each if statement. and one more important thing about else statement is it is always considered a condition of if statement that just before the else statement.


syntax:


if(condition){


    statements to be executed when a condition becomes true


}else{


    statements to be executed when a condition becomes false.


}


Note: in C the o is considered as false and any other value is considered as the true value so if I write if(o) then it is always going to false  and one more thing that people like me always forgot that for checking  condition for comparing variable or something else, we need to write double equal ( == ) sign rather then only one single equal sign so always remember that


Example:


else-if statement:


In program, if we the if statements condition become false and then we want to check other condition then we use else-if statement


syntax:


else-if(condition ){

        statements to be executed when this particular condition becomes true

}