If statement | Condition | Check | Checking condition
If statement is a checking condition in C++ language and many others also.
By this we can impose a check point and control the flow of program during the
execution of the program. The if statement is firstly check the given criteria
and then execute the statement or block of statements. The if statement is very
important in any language. It is called by many names as if statement, if
condition, if and check.
Usage:
If condition (only if not nested if) is used in that place where we have check one condition and then execute some statements. If the condition become true or satisfy the statements or block of statements written very next after if condition, execute and if the condition become false or unsatisfying then the program ignore the statements or block of statements written very next after if condition and control transfer to other statement.
For example:
If name is Ali then display you are log in
If Number is 50 or greater than 50 then display pass
If the user input wrong value or exceed limits it then show a message
If the condition become true, the statements are executed but if not......Nothing is executed.
We have else option for two way execution.
If we want that there are two way of execution we use else option.
If number is 50 or greater than 50 than display pass otherwise display fail.
By this method we can apply one way testing and two way executions.
(Note: else option is not essential to if but if is essential to else )
General syntax:
If (Condition)
cout<<”You are pass……”;
else
cout<<”You are fail…….”:
For example :
If (n>=50)
Usage:
If condition (only if not nested if) is used in that place where we have check one condition and then execute some statements. If the condition become true or satisfy the statements or block of statements written very next after if condition, execute and if the condition become false or unsatisfying then the program ignore the statements or block of statements written very next after if condition and control transfer to other statement.
For example:
If name is Ali then display you are log in
If Number is 50 or greater than 50 then display pass
If the user input wrong value or exceed limits it then show a message
In If condition there is only one way
testing and one way execution; means
If the condition become true, the statements are executed but if not......Nothing is executed.
We have else option for two way execution.
If we want that there are two way of execution we use else option.
For example:
If Name is Ali then
display you are log in otherwise display your name is incorrect.If number is 50 or greater than 50 than display pass otherwise display fail.
By this method we can apply one way testing and two way executions.
(Note: else option is not essential to if but if is essential to else )
General syntax:
If (Condition)
cout<<”You are pass……”;
else
cout<<”You are fail…….”:
For example :
If (n>=50)
cout<<”You are pass”;
else
Ali Haider
Comments
Post a Comment