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

yes they are called ternary operator i will tell how they work so here is it

Syntax Condition ? Value1 : Value 2

How it works?-- If the condition is true then it returns Value1 and if condition is false then it returns Value2

Examples and its outputs-
taking an simple example --
pawn Code:
//Example
new a,b,c;
b=10;
c=20;
a= (b<c) ? 1 : 0;
So in the above example the value of a will finally be 1 because the condition is true if condition had been (b>c) then value of a will be 0

There is more complex way of using it by using one ternary operator inside another those are used in place of nested loop and are very difficult to understand

I recommend you to use this only when you have a simple if else statement condition. Only if you are expertise in it then use it in place of nested if-else
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: 2 Guest(s)