Skip to main content

If And Else Conditional Structure In C++




If

If is a keyword, which is use as a conditional operator. If keyword execute the statement only if condition is fulfilled.

if (condition) statement.












If-else

When if condition are false then the statement of else condition can execute

if (condition) statement1 else statement2.


In this code “a=10”,”b=9” there are not equal , so “if(a==b)” condition is not true .
the output is….



If-else-if

When 1st if condition can false then it execute else. If we want we can add more if condition with else.
if (condition) statement 1 else if (condition) statement 2 else.




In this code “a=10”,”b=9” there are not equal , so “if(a>b)” condition is not true .
the output is….



Comments

Popular posts from this blog

Switch, Case, Default Statements In C++

Switch case is uses as alternative of if….else. When we need to use long term of if…else then we use switch case for reducing program execution time. syntax: Switch(variable){ Case value 1: Statement; Break; Case value 2: Statement; Break;

do...while loop in C++

The do while loop is very similar to while loop . In the while loop first check final condition then execute the statement. But in the do while loop first execute the statement then check the final condition. Syntax: Initialization; Do{ increment/decrement;   } while(Final condition)

Input & Output In C++ (Basic)

Cout<<”Print sentence”;     This statement is use to print out any kinds of sentence or string type values. Cout<<345;     This statement is use to print out any kinds of numeric numbers, without change. Cout<<variable;        This statement is use to print the value of variable. The value of the which variable we want to print, It is need to write that variable on variable place.