CH04 : Control Statement in C

Two types of Control Statement :

  • if-else statement
  • switch statement


If-else statement ### `If-else` :

If-else statement is used to execute a statement block or a single statement depending on the value of a condition.

**syntax** : ```c if (condition) { ------------ ------------ } else { ------------- ------------- } ``` Where `conditon` is a logical expression which will have the value of true or false. </details>
Nested if-else statement ### nested if-else statement

An if statement may have another if statement in the `true block` and `false block`.This compound statement is called nested if statement.

**syntax** : ```c if (condition 1) { if (condition 2) { -------------- <true block 1> -------------- } else { ------------- <false block 1> ------------- } } else { if (condition 3) { -------------- <true block 2> -------------- } else { --------------- <false block 2> --------------- } } ```
Switch Statement ### switch statement

switch statement is used to create a block of statements depending on the value of a variable or an expression.

**syntax** : ```c switch ( ) { case <label 1>: { ------------- <statement block 1> ------------- break; } case <label 2>: { ------------- <statement block 1> ------------- break; } case

Table of contents