Confused with symbols. ("?", ":")
#8

It's an alternative to 'if' and 'else'.

pawn Code:
if(cond == true)
{
    if(cond2 == true) var = 15;
    else if(cond2 == false) var = 25;
}
else if(cond == false) var = 60;
Could be written as:
pawn Code:
new var = (cond == true) ? ((cond2 == true) ? (15) : (25)) : (60);
Personally, since I discovered ternary operators, I have loved them because they reduce everything into 1 simple line and their concept is easy to grasp. They are very useful. Slice's thread gives a very good example of their usage.
Reply


Messages In This Thread
Confused with symbols. ("?", ":") - by Faisal_khan - 01.06.2014, 11:07
Re: Confused with symbols. ("?", ":") - by Rittik - 01.06.2014, 11:09
Re: Confused with symbols. ("?", ":") - by Faisal_khan - 01.06.2014, 11:12
Re: Confused with symbols. ("?", ":") - by Rittik - 01.06.2014, 11:15
Re: Confused with symbols. ("?", ":") - by BroZeus - 01.06.2014, 11:18
Re: Confused with symbols. ("?", ":") - by Faisal_khan - 01.06.2014, 11:18
Re: Confused with symbols. ("?", ":") - by Faisal_khan - 01.06.2014, 11:24
Re: Confused with symbols. ("?", ":") - by Threshold - 01.06.2014, 13:54

Forum Jump:


Users browsing this thread: 5 Guest(s)