> For the complete documentation index, see [llms.txt](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/03-programming-basics-ii/homework/01.-difference-between-if-and-switch.md).

# 01. Difference between if and switch

The `if` statement has a condition part that can:

1. Take any integer or boolean value
2. If integer is non zero or boolean is true
   1. Execute the true block
3. else
   1. Execute the false block

The `switch` statement can take an expression that evaluates to an integer or enumeration.

1. It matches the value of the expression with cases
2. When match is found
3. the lines after that case is executed.

The `if` statement can take any kind of boolean expression while the switch statement can only take integer expressions that maps for equality.
