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)

For Loop In C++

A loop can repeat the statement of a particular job continuously for a specific number of times. Loop Description Syntax For The condition can tested before statement execution.   For(Initialization, Final condition, increment /decrements ) { statement; } while First it check the condition then do the job. Initialization; While(Final condition) { Statement; increment /decrements; } Do..while First do job then test the condition. Initialization; Do{ Statement; increment /decrements; } While(Final condition)