Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-02-2009
Member
 
Join Date: Jan 2009
Posts: 71
IF Statement to Execute multiple Conditions

I am wondering if this is possible in real time programming environment or if there really isn't a way to do it. I want to make an IF statement that triggers on multiple conditions.

ie.
Code:
IF statement
(condition 1 is true)
     and (condition 2 is true)
           {
               //  Perform action
           }
Is there a way? If not through an "IF" statement, then any suggestions?

Thanks!
Reply With Quote
  #2  
Old 10-02-2009
Member
 
Join Date: Mar 2008
Posts: 258
Re: IF Statement to Execute multiple Conditions

Hi,

For your querries you can make use of ElseIf condition where you need to specify one single main If condition then just have to describe the ElseIf condition and that may be any number of conditions. The Else If condition logic will be such that if your First IF condition does not satisfy then it will directly print the ending Else condition and if it satisfies then it will go into the inner loop and at the moment condition fails it will print the immediate else condition next to it.

hope this will clears your doubt.
Reply With Quote
  #3  
Old 10-02-2009
Member
 
Join Date: Dec 2008
Posts: 202
Re: IF Statement to Execute multiple Conditions

Whatever the Khushal has explain in its earlier post is absolutely right like that way you can achieve the single If condition with the Multiple condition criteria.
Here i will explain some IFElse related things which i feel to be clear with you.Each else clause belongs to the nearest preceding if statement. Because of this, it is not possible to have one catch all else clause act as a net for multiple if statements just because it follows a series of them. One final else clause can, however, act as a catch all net as long as each if statement, beginning with the second, is preceded by an else. The final else will then perform as a catch all because all the if statements are now attached to each other by the else statements.

Code:
 if (name == "mini") {
    alert("your name is mini")
    }
    else if (name == "harold") {
    alert("your name is harold")
    }
    else if (name == "fred") {
    alert("your name is fred")
    }
    else {
    alert("Your name is not mini, harold or fred")
    }
Reply With Quote
  #4  
Old 10-02-2009
Member
 
Join Date: Jan 2009
Posts: 140
Re: IF Statement to Execute multiple Conditions

I would use a switch statement for multiple conditions.

Code:
switch(varname)

{

case "once":

dothis();

 

break;

case "twice" 

dosomethingelse();

break;

default:

dothat();

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "IF Statement to Execute multiple Conditions"
Thread Thread Starter Forum Replies Last Post
How to execute Server.Execute function in ASP.NET (C#) RasMus Software Development 3 25-09-2009 12:30 PM
Which is the best camera for rugged conditions Deabelos Portable Devices 2 01-06-2009 12:23 PM
Simulate the varying conditions Aamin Software Development 3 26-02-2009 11:18 AM
What is the difference between while statement & do statement? Athos Software Development 4 25-02-2009 08:52 PM
Windows XP freezes at Welcome Screen under all conditions Miambi Windows XP Support 1 11-07-2007 07:34 PM


All times are GMT +5.5. The time now is 02:18 PM.