If Statements

If statements allow for selective execution of instructions. If the condition specified evaluates to true, then the following instruction/instruction block will be executed. Otherwise, the following instruction/instruction block will be skipped.

Syntax

  1. if(condition)
    1. Instruction;

--or--

  1. if(condition)
  2. {
    1. Instruction Block
  3. }

Example

  1. void main()
  2. {
    1. int a = 3;
    2. if(a==2)
    3. {
      1. printf("\nSince A=3, this won't be printed");
    4. }
    5. if(a==3)
    6. {
      1. printf("\nSince A=3, this will be printed");
    7. }
  3. }