C if statement
Syntax :
if(expression) statement1;
Explanation :
- Expression is Boolean Expression
- It may have true or false value
- It Checks whether the given Expression is Boolean or not !!
- If Expression is True Then it executes the statement otherwise jumps to next_instruction
Sample Program Code :
void main() { int a=5,b=6,c; c = a + b ; if (c==11) printf("Execute me 1"); printf("Execute me 2"); }
Output :
Execute me 1
If Statement :
if(conditional) { Statement No 1 Statement No 2 Statement No 3 . . . Statement No N }
Note :
- More than One Conditions can be Written inside If statement.
- Opening and Closing Braces are required only when “Code” after if statement occupies multiple lines.
if(conditional) Statement No 1 Statement No 2 Statement No 3
In the above example only Statement 1 is a part of if Statement.
- Code will be executed if condition statement is True.
- Non-Zero Number Inside if means “TRUE Condition”
if(100) printf("True Condition");