Multiple if conditions – CSKC
Sign In

Search

Code Learning #CPP#1947    siteicon   siteicon  

Multiple if conditions

Using multiple if conditions which are often redundant in nature.

Learning Objectives

  • Learning to use multiple if conditions which are often redundant in nature.

Source Code

TC++ #1947

 

Source Code

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

Alternate (?) :   Related ( ? ) :

Code Understanding

if(a==b)
cout<<“A is equal to B”<<endl;
if(a>b)
cout<<“A is greater than B”<<endl;
if(a<b)
cout<<“A is smaller than B”<<endl;
All the three conditions above are independent of each other and are checked even if one has been checked and found true. For e.g. if first one is true than check for second and third condition is redundant.

Notes

  • The check for multiple if for related mutually exclusive conditions will have some degree of redundancy. This may however be useful in some cases where check for first condition my be most commonly occurring and we do not want to do further checks at all.

Common Errors

  • Multiple ifs can almost universally be replaceable with if-else constructs, use them consciously when you what you are doing say for increasing efficiency in some cases. Usually they will reduce run time efficiency.


Suggested Filename(s): multiple-if.cpp



Share

Created: 27-Dec-2017 18:00 | Updated: 15-Sep-2018 11:52|