If Statement



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 08/06/2010 at 16:06, xxxxxxxx wrote:

    Is there any benefit over doing an if statement like this?

    x == 10 ? y = 16 : y = 5;
    

    as opposed to

    if (x = 10)
    {
    	y = 16;
    }
      
    else
    {
    	y=5;
    }
    

    Thanks,

    Shawn



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 09/06/2010 at 02:27, xxxxxxxx wrote:

    The only real benefit is that it's shorter. You can also use the ? operator in function calls.

    Example:

    MyFunction(x == 10 ? 16 : 5);
    

    as opposed to

      
    if (x == 10)  
      MyFunction(16);  
    else  
      MyFunction(5);  
    

    cheers,
    Matthias


Log in to reply