Home of RF and Wireless Vendors and Resources

One Stop For Your RF and Wireless Need

if-statement vs switch-stament

This page on if-statement vs switch-stament describes difference between if-statement and switch-stament. Both are used for the same application and are C programming language statements. Following are the syntax for these instructions.


If else statement:
If (conditioncheck1 )
{
//Statements (one or many)
}
else if(conditioncheck2 )
{
//Statements(one or many)
}
else if(conditioncheck3 )
{
//Statements(one or many)
}

else
{
//Statements(one or many)
}

Switch statement:
Switch (condition)
{
Case condition1: //statements
Case condition2: //statements
Case condition3: //statements
Default: //statements
}

switch-stament is better in performance and easy to read compare to if-statement

When variable part is call to the function then also switch delivers better performance.

In case of more than two conditions and matching case is too down, then if-else introduces more delay as all the conditions need to be checked before program reaches to the matching case. At the same time switch statement executes faster for any match case as the check is performed at the start.

RELATED LINKS

C Programming Language tutorial

What is Difference between

difference between FDM and OFDM
Difference between SC-FDMA and OFDM
Difference between SISO and MIMO
Difference between TDD and FDD
Difference between 802.11 standards viz.11-a,11-b,11-g and 11-n
OFDM vs OFDMA
CDMA vs GSM
Bluetooth vs zigbee
Fixed wimax vs mobile

RF and Wireless Terminologies


Share this page

Translate this page