Within programs we very often want to execute a different section of code, depending upon various conditions within C the If statement is used to achieve this. The If statement consists of two parts namely
if (relational expression)
{
operation;
operation;
}
else
{
operation;
operation;
}
The relational expression of the statement is a logical expression i.e. A== 50, the expression is true if A indeed contains the integer 50. Other logical expressions are valid i.e.
== Equals
> greater than
< less than
>= greater than or equal to
<= less than or equal to
!= not equal to
e.g.
if ( x== 3.142)
{
printf("I have found pi\n\r");
}