How to use "Boolean"
#7

? true : false is called ternary operator.

It's a easy way to replace this:

pawn Код:
if(condition)
{
    var = value;
}
else
{
    var = anothervalue;
}
With this:

pawn Код:
var = (condition) ? value : anothervalue;
'?' = if the condition proceeds
':' = else

Some examples:

pawn Код:
new value = 5;
new bool: isfive = (value == 5) ? true : false;
pawn Код:
new string[] = "hello world";
new bool: isempty = (strlen(string)) ? false : true;
pawn Код:
new Float: value = 0.0;
print("The float value %s.", (value > 0.0) ? ("isn't null") : ("is null"));
Reply


Messages In This Thread
How to use "Boolean" - by mrkiller90 - 17.07.2014, 14:54
Re: How to use "Boolean" - by PrivatioBoni - 17.07.2014, 14:56
Re: How to use "Boolean" - by mrkiller90 - 17.07.2014, 14:59
Re: How to use "Boolean" - by Dignity - 17.07.2014, 14:59
Re: How to use "Boolean" - by PrivatioBoni - 17.07.2014, 15:00
Re: How to use "Boolean" - by mrkiller90 - 17.07.2014, 15:02
Re: How to use "Boolean" - by paulommu - 17.07.2014, 15:07
Re: How to use "Boolean" - by mrkiller90 - 17.07.2014, 15:17

Forum Jump:


Users browsing this thread: 1 Guest(s)