Results 1 to 4 of 4

Thread: IF Statement to Execute multiple Conditions

  1. #1
    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!

  2. #2
    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.

  3. #3
    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")
        }

  4. #4
    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();
    
    }

Similar Threads

  1. How to execute Server.Execute function in ASP.NET (C#)
    By RasMus in forum Software Development
    Replies: 3
    Last Post: 25-09-2009, 12:30 PM
  2. Which is the best camera for rugged conditions
    By Deabelos in forum Portable Devices
    Replies: 2
    Last Post: 01-06-2009, 12:23 PM
  3. Simulate the varying conditions
    By Aamin in forum Software Development
    Replies: 3
    Last Post: 26-02-2009, 11:18 AM
  4. Replies: 4
    Last Post: 25-02-2009, 08:52 PM
  5. Windows XP freezes at Welcome Screen under all conditions
    By Miambi in forum Windows XP Support
    Replies: 1
    Last Post: 11-07-2007, 07:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,717,394,212.62034 seconds with 16 queries