C language has two keywords if, else to make decision. If block has one condition or comparison statement which decides if this logic would follow the path of "IF" or "ELSE". Syntax for if-else block is

if (condition )  
  Statement 
else 
  Statement
Or 
if (condition )  {
  Statement (s)
10   } else {
11    Statement (s)
12  }

Curly brackets are not needed if only one statement is there. But it is recommended to put Curly bracket to have better readability. Here is

if (condition 1)  {
  Statement (s)
} else if (condition2) {
  Statements (s)
  .............
  .............
} else if (condition n) {
  Statements (s)
} else {
10    Statements (s)
11  }

You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.

 Vote 1

Similar topics related to this section

global vs static variable, register vs auto variable, const, sizeof void, if, if-else, if-else-if, label and goto, switch case, compare with ==, execution sequence,

# C Programming Language (Prentice Hall Software)
# Let Us C Paperback - 2006 by Yashavant Kanetkar
# Understanding and Using C Pointers Core techniques for memory management
# Data Structures Using C and C++ Paperback - 1998
# Data Structures In C Paperback - August 11, 2008 by Noel Kalicharan