Logical Conditions



The logical expressions will always result either true or false. We can use four relational operations (<, <=, >, >=) the two equality operators (== , !=) or logical (&& (AND), || (OR))
Ex: - a>4;
Count==0;

Branching

C provides us different C statement which is used to conditionally execute a block of code.

1. If statement/ if-else statement

The if else statement is used to carry out a logical test & then take one of two possible actions depending on the outcome of the test.

Syntax:-
     if (condition)
          {
               Statement 1
               Statement 2
               -
               -
               -

          }
     else
          {
               Statement
               _
               _
               _
          }
     Next statement
               _
               _
               _
               _

If condition is true then statement with in if block are executed & then programming control is transferred to next statement.

If condition is false then statement with in else block are executed & then program control is transferred to next statement.

Else block is optional

Syntax:-
    if (condition)
        {
            -
            -
            -
    Next statement
            -
            -
            -
        }

Flow chart of if-else statement.