if (test_condition)

It takes an expression in parenthesis and a statement or block of statements. If the expression is true then the statement or block of statements gets executed otherwise these statements are skipped.

Flowchart:
Syntax:
  if (test_condition)
  {
    //execute_this_block
  }

if/else

  • An if statement may be followed by an optional else statement, which executes when the expression (test condition) is false.
  • if/else allows greater control over the flow of code than the basic if statement, by allowing multiple tests to be grouped together.
Flowchart:
ifelse
Syntax:
if (test_condition)
 {
  // action A
 }
else
 {
  // action B
 }