Ternary operator problem
#1

syntax

Code:
condition ? true : false
Normal if - else

pawn Code:
if(Day < 21)
{
    SetWeather(WinterWeather[winterrand]);
}
else
{
    SetWeather(SpringWeather[springrand]);
}
with ternary operator

pawn Code:
(Day < 21) ? SetWeather(WinterWeather[winterrand]) : SetWeather(SpringWeather[springrand]);
i get this warning

Code:
warning 215: expression has no effect
what i wrong ?
Reply
#2

pawn Code:
if((Day < 21) ? SetWeather(WinterWeather[winterrand]) : SetWeather(SpringWeather[springrand])){}
Reply
#3

Quote:
Originally Posted by Jeffry
View Post
pawn Code:
if((Day < 21) ? SetWeather(WinterWeather[winterrand]) : SetWeather(SpringWeather[springrand])){}
i get a warning with empty statement
Reply
#4

pawn Code:
SetWeather((Day < 21) ? (WinterWeather[winterrand]) : (SpringWeather[springrand]));
Reply
#5

Quote:
Originally Posted by Speed++
View Post
i get a warning with empty statement
I compiled it, it worked without warnings.
Reply
#6

Why bother using it? It will still compile the same as using if/else and is harder to read.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)