Conditional operator ?

Hello, just wondering how I would add an "else if" statement to the following.
(weather == "hail") ? trace("bringMotorcycleHelmet") : trace("bringStrawHat");
thanks for any help.

You can "nest" them like so:
(weather == "hail") ? trace("bringMotorcycleHelmet") : ((weather == "catsndogs") ? trace("takeshelternow"):
trace("bringStrawHat"));
But you're probably better using switch if you have a lot of weather states, something like
switch (weather){
case "hail":
trace( 'bring motorcyle helmet')
break;
case "catsndogs":
trace( 'take shelter now')
break;
case "sunny":
trace( 'apply sunsreen')
break;
default:
trace( 'do whatever you like, I am unfamiliar with that type of weather')
break;

Similar Messages

  • Powershell equivalent of a conditional operator?

    Hi,
    I've got a small snippet of Powershell code that works perfectly well, but I'd like to make it better. here it is:
    if ($discoveredIssues.Length -gt 0){
    $returnHash += @{"IsBatchValid"=$false}
    else{
    $returnHash += @{"IsBatchValid"=$true}
    I don't like the fact that the string literal "IsBatchValid" exists in two places as there's always the chance that someone could change it one place and not the other (very minor quibble, I know).
    I was wondering if there was a way to write this such that I don't have the if...then...else. I tried to do this:
    $returnHash += @{"IsBatchValid"={if ($discoveredIssues.Length -gt 0){$false}else{$true}}}
    but that doesn't work. It just returns "if ($discoveredIssues.Length -gt 0){$false}else{$true}}" rather than the actual result of that expression. I was hoping there might be something like C#'s conditional operator so that I could do something
    like this:
        $discoveredIssues.Length -gt 0 ? $false : $true
    but sadly not.
    Any ideas how I can achieve this? I suspect there isn't a way, but it'd be nice if there were.
    thanks
    Jamie

    $returnHash.IsBatchValid = $discoveredIssues.Length -gt 0
    Oh nice. Didn't quite work. Powershell ISE complained:
    But it prompted me to go away and change it to this:
    $returnHash += @{"IsBatchValid"=$discoveredIssues.Length -eq 0}
    which I suppose would have been obvious had I bothered to pay any attention to what I was doing. Always pays to have someone else put eyes on something. thanks mjolinor.
    Glad to help.
    It wasn't obvious from the code whether $returnHash already exists or not.  I was assuming it did:
    $returnHash = @{}
    $returnHash.IsBatchValid = $discoveredIssues.Length -gt 0
    $returnHash
    Name Value
    IsBatchValid False
    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

  • Conditional operator question?

    Hello,
    Quick question, are we not allowed to use the conditional operator this way... see code below:
    char volatile ProgString_[] = "\
    {Fan code} \
    12 <Limit11> [C1_ACM2]_[B1] _AND_ \
    bla bla \
    unsigned char UPC_SYSZ_EndOfTable(unsigned long i){ // Find the double '*' in string
    char volatile *u;
    u = &ProgString_[i];
    if(!(strncmp("*", u, 1))){
    i++;
    u = &ProgString_[i];
    if(!(strncmp("*", u, 1))){
    return TRUE;
    else {
    return FALSE;
    else
    return FALSE;
    void UPC_SYSZ_Parse(){
    unsigned char volatile iOCntr = 0;
    unsigned long volatile i;
    for(i=0; i<200; i++){
    (UPC_SYSZ_EndOfTable(i))?(break):(continue); //<<<<< Invalid expression ??
    I would of used the following compact line:
    (UPC_SYSZ_EndOfTable(i))?(break):(continue);    //<<<<< Invalid expression ??
    to periodically test the end of the string by fetching the "EndOfTable() function and evaluating if the double star is detected.
    If detected, I would break out of the for loop, if not then I would continue.
    Is it possible to do it this way?
    thanks for all help!
    r

    Think of it along the lines of each of the operands of the ternary operator must produce a value (which of course break and continue being statements cannot do).
    Based on your brief example here is what I would do
    for(i=0; i<200; i++){
    if (UPC_SYSZ_EndOfTable(i)) break;
    // doesn't make any sense to put more code down here anyway, so no real point to continue}

  • Conditional Operator for Popup Pages!!

    Hi All,
    In my application there are 2 two different pages say 85 and 45. In page 85 i am calling the Iframe in which it will redirect to page 45. Now in that page i.e 45 i have used template as popup. In that i have an IR and HTML regions and a button in IR region. when i click on button then only should show the HTMl Region for that i ahave used conditional operator. But that is not working!!
    So i would like to know wheather conditional will work popup pages. If not let me know the procedure for that!!!!
    Thanks,
    Anoo..

    .. Apart from that, there is no need for your original long list of "if .. else". For a list of possible inputs, you should consider something like this:
    switch(myYear.selection.text)
    case "10": yearSelect=0; break;
    case "11": yearSelect=1; break;
    case "12": yearSelect=2; break;
    case "13": yearSelect=3; break;
    case "14": yearSelect=4; break;
    default: yearSelect=5;
    or, with your input and output, something as simple as
    yearSelect = Number(myYear.selection.text)-10;
    -- but I don't know what your possible range of inputs is. If it's "anything goes", you have to check for a not-in-range and then set it to your default of 5.

  • Conditional operator and nulltype

    hi,
    i have a little problem, it's actually not really a problem, im just curious. i have the following testclass
    public class Test{
      public static void main(String[] args) {
        Double a = false? 1.00: (Double)null; // nullpointer (A)
        Double b = false? 1.00: null;  // works (B)
    }when line (A) is uncommented a NullPointerException is thrown and i have no idea why.
    when i comment out line (A), line (B) works. because the type of the conditional operator is of the other if one of them is NullType.
    so not really a problem because it's better to use (B) but i still want to know why (A) doesn't work.
    Edited by: creichlin on Oct 27, 2008 12:15 PM

    ouch, i am just to stupid. i forgot autoboxing, the NullType is cast to a null Double, then it's autoboxed to a double and then to a Double again.

  • Conditional Operator for else if?

    I used the google compiler on one of my scripts. It worked fine except I am getting hung up on some of the conditional statements it made. Originally I had a series of if else if statements. When changed to Conditional Operator it changes the fuctionality of it. Here we go if anyone can help I will take any tips.
    My version:
    if(myYear.selection.text=="10"){yearSelect=0;}
             else if(myYear.selection.text=="11"){yearSelect=1;}
             else if(myYear.selection.text=="12"){yearSelect=2;}
             else if(myYear.selection.text=="13"){yearSelect=3;}
             else if(myYear.selection.text=="14"){yearSelect=4;}
            else{yearSelect=5;}
    Google version:
    yearSelect="10"==b.selection.text?0:"11"==b.selection.text?1:"12"==b.selection.text?2:"13"==b.selection.text?3:"14"==b.selection.text?4:5,
    Thanks in advance for any advice.
    Brett.

    .. Apart from that, there is no need for your original long list of "if .. else". For a list of possible inputs, you should consider something like this:
    switch(myYear.selection.text)
    case "10": yearSelect=0; break;
    case "11": yearSelect=1; break;
    case "12": yearSelect=2; break;
    case "13": yearSelect=3; break;
    case "14": yearSelect=4; break;
    default: yearSelect=5;
    or, with your input and output, something as simple as
    yearSelect = Number(myYear.selection.text)-10;
    -- but I don't know what your possible range of inputs is. If it's "anything goes", you have to check for a not-in-range and then set it to your default of 5.

  • NEED HELP:To Parse Conditional Operator Within An Expression.

    Hi there:
    I'm having some difficulties to parse some conditoional operator. My requirements is:
    Constants value: int a=1,b=2,c=3
    Input/Given value: 2
    conditional operator expression: d=a|b|c
    Expected result: d=true
    Summary: I like to receive a boolean from anys expressions defined, which check against Input/Given value.Note: The expression are various from time to time, based on user's setup, the method is smart enough to return boolean based on any expression.
    Let me know if you have any concerns.
    Thanks a million,
    selena

    here is a simple example.
    BNF changes
    EXPR ::= OPERATOR
    EXPR ::= OPERATION OPERANT EXPR
    This is as far as I can go, please use it as a template only
    because you need to take into account the precedence using ()
    the logic of the eval was simply right to left so I think it is not what you want
    Cheers
    public interface Expression
         String OR = "|";
         String AND = "&";
         public boolean eval(int value) throws Exception;
    public class ExpressionImpl implements Expression
         public String oper1;
         public String operant;
         public Expression tail;
         /* (non-Javadoc)
          * @see parser.Expression#eval()
         public boolean eval(int value) throws Exception
              int val1 = getValue(oper1);
              if (null == tail)
    System.out.println(val1 + ":" + value);               
                   return (val1 == value);
              else
                   if (OR.equals(operant))
                        return (val1 == value || tail.eval(value));
                   else if (AND.equals(operant))
                        return (val1 == value && tail.eval(value));
                   else
                        throw new Exception("unsupported operant " + operant);
         private int getValue(String operator) throws Exception
              Integer temp = ((Integer)Parser.symbol_table.get(operator));
              if (null == temp)
                   throw new Exception("symbol not found " + operator);
              return temp.intValue();
         public String toString()
              if (null == operant) return oper1;
              return oper1 + operant + tail.toString();
    public class Parser
         public static HashMap symbol_table = new HashMap();
          * recursive parsing
         public Expression parse(String s)
              ExpressionImpl e = new ExpressionImpl();
              e.oper1 = String.valueOf(s.charAt(0));
              if (s.length() == 1)
                   return e;
              else if (s.length() > 2)
                   e.operant = String.valueOf(s.charAt(1));
                   e.tail = parse(s.substring(2));
              else
                   throw new IllegalArgumentException("invalid input " + s);
              return e;
         public static void main(String[] args) throws Exception
              Parser p = new Parser();
              Parser.symbol_table.put("a", new Integer(1));
              Parser.symbol_table.put("b", new Integer(2));
              Parser.symbol_table.put("c", new Integer(3));
              Parser.symbol_table.put("d", new Integer(4));
              Expression e = p.parse("a|b|c&d");
              System.out.println("input " + e.toString());
              System.out.println(e.eval(2));
    }

  • What is the conditional operator for AND, OR .....?

    what is the conditional operator for AND, OR .....? in ABAP language...
    AND, OR .. & is not accepting or recognising.
    Is these feature available in abap ??? if yes, how to use?
    thanks...
    shiva

    Hi,
    Conditional operator for AND and OR are same AND and OR.
    A logical expression consists of comparisons (see expressions 1 to 4 below) and/or selection criteria checks (expression 5) using the operators AND, OR and NOT , as well as the parentheses " (" and ")".
    The individual operators, parentheses, values and fields must be separated by blanks:
    Incorrect:
    f1 = f2 AND (f3 = f4).
    Correct:
    f1 = f2 AND ( f3 = f4 ).
    NOT takes priority over AND, while AND in turn takes priority over OR:
         NOT f1 = f2 OR f3 = f4 AND f5 = f6
    thus corresponds to
         ( NOT ( f1 = f2 ) ) OR ( f3 = f4 AND f5 = f6 )
    The selection criteria comparisons or checks are processed from left to right. If evaluation of a comparison or check proves part of an expression to be true or false, the remaining comparisons or checks in the expression are not performed.
    All data objects that can be converted among each other can be used as operands for logical expressions.
    Check if u are using the AND or OR operator this way.
    IF f1 AND f2.
    ENDIF.
    In this case it will throw error. Here it act as relational operator.
    Regards,
    Prakash

  • SSRS Using Sum and = in a conditional operator

    Hi,
    Still getting to grips with SSRS so any help would be appreciated.
    My aim is to calculate a conditional field using the SSRS expression feature, the datasource is a shared dataset which i can't alter so i can't just go an alter the SQL query or anything.
    In SQL my query would be like this: SELECT COUNT(TotalHours) FROM TableName WHERE TotalHours <= 24
    Is there anyway to combined the Iff and Sum operator's to get a result like the above?
    At present all i managed to come up with is the below but obviously it's not returning the correct amount.
    =IIf(Fields!TotalHours.Value <= "24", Sum(Fields!TotalHours.Value), 0 )
    Please help!
    Edit: Please note that i'm not trying to sum a field based on a condition that relates to another column, i just need a sum of 'TotalHours' that are less than or equal to 24, please also note there is another field called category, each category needs a
    sum of the above.
    Regards,
    Marcus
    Plain_Clueless

    Hi Marcus,
    According to your description, you want to count [TotalHours] when the value of this field is less than 24, right?
    In your scenario, you could use the expression like below:
    =Sum(IIF(Fields!TotalHours.Value<=24,1,0))
    Please note don’t put this expression in the detail rows, you could refer to our test results:
    If you have any question, please feel free to ask.
    Best regards,
    Qiuyun Yu
    Qiuyun Yu
    TechNet Community Support

  • Related to conditional operator

    hai SDNs,
    in select stmt or delete stmt in where clause i have condition like this:
    need the somes values based on condition "A" is in the range 10 - 1000.
    how to write it in where clause...
    what is the operator or any alternative???
    thanking you,

    You should use BETWEEN operator OR you can use RANGES / SELECT-OPTIONS if you are writing this in ABAP.
    SELECT * FROM MARA WHERE MATNR BETWEEN '1' AND '10000'.
    T_RANGES-SIGN = 'BT'.
    T_RANGES-OPTION = 'EQ'.
    T_RNAGES-LOW = '1'.
    T_RANGES-HIGH = '1000'.
    APPEND T_RANGES.
    SELECT * FROM MARA WHERE MATNR IN T_RANGES.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • 'AND' Conditional operator in smartform

    Hi experts,
    I have  to use AND condition in smartform (text).
    For OR condition there is a standard icon sothat can use.
    But how can we get AND contion in smartform.
    if I am giving AND condition it is showing error
    I have tries in SDN before posting my problem but i couldn't get solution for that
    Please help me out of this problem.

    Hi Saravanan,
    You dont need to give AND condtion. Just give two conditions in the conditions tab. it will work
    Regards
    Shanly

  • When will C# get a REAL null-conditional operator?

    I program in SWIFT and C# and I'm bummed to come back to C# for one reason.   The freaking NULL REFERENCE error is a language design problem that I realized SWIFT avoided.    Every type in SWIFT is either optional or not-optional, so there
    is not a possibility of evaluating a null because non-optional types must be unwrapped with a null coalescing operator before you can evaluate it.
    It seems like a problem easily fixed, why is there no operator like this in C#? (or maybe there is I don't know)
            private CommandLineOptions GetOptions(string[] args)   {
                if (args?[0] == "i")     {
                    // yay for not having to test ArgumentNullException and writing 
                    // if(args != null && args[0] == "-i") ...
    Scott Weeden

    Hello ScrottWeeden,
    I dont know how this works in SWIFT, but what I know is the importance of NULL in c#.
    For example, you can use NULL to show that a value is not set.
    E.g:
    object _o
    //... Work with _o;
    if(_o != null) { //_o is not null, we can work with it!
    _o.ToString();
    } else {
    //_o is NULL, handle this error
    // -- OR --
    try {
    _o.ToString();
    } catch(Exception ex) { //Error, if o is NULL. So can use ReferenceNullException insted of general Exception.
    So, you can use to show tha an process failed, that data is invalid or something more.
    PS: Struct is not allowed to konvert to null. (But you can use the followng code to avoid this:)
    struct MyStruct {
    //See: https://msdn.microsoft.com/de-de/library/b3h38hb0.aspx
    MyStruct? _mstr;
    if(_mstr.HasValue) //Is not NULL
    //Real value
    _mstr.Value;
    //Set Null
    _mstr = null;
    © 2015 Thomas Roskop
    Germany // Deutschland

  • Conditional operator in where clause?

    I have 4 assignable parameters for filtering records. If a parameter is not assigned the filter is ignored. This is working fine with the SQL-statement below except for one scenario: if none of the parameters are assigned I get no records at all but then I need all of the records.
    with t as
        select 1 as val, 'a' as var from dual union all
        select 2 as val, 'a' as var from dual union all
        select 3 as val, 'b' as var from dual union all
        select 4 as val, 'b' as var from dual union all
        select 5 as val, 'b' as var from dual union all
        select 6 as val, 'c' as var from dual union all
        select 7 as val, 'd' as var from dual union all
        select 8 as val, 'e' as var from dual union all
        select 9 as val, 'e' as var from dual union all
        select 0 as val, 'f' as var from dual
    select *
    from t
    where t.var = decode(:pvar1,'',null,:pvar1)
    or t.var = decode(:pvar2,'',null,:pvar2)
    or t.var = decode(:pvar3,'',null,:pvar3)
    or t.var = decode(:pvar4,'',null,:pvar4)

    You need no "OR"s
    <br>
    SQL> var pvar1 char
    SQL> var pvar2 char
    SQL> var pvar3 char
    SQL> var pvar4 char
    SQL> with t as(    select 1 as val, 'a' as var from dual union all
      2      select 2 as val, 'a' as var from dual union all
      3      select 3 as val, 'b' as var from dual union all
      4      select 4 as val, 'b' as var from dual union all
      5      select 5 as val, 'b' as var from dual union all
      6      select 6 as val, 'c' as var from dual union all
      7      select 7 as val, 'd' as var from dual union all
      8      select 8 as val, 'e' as var from dual union all
      9      select 9 as val, 'e' as var from dual union all
    10      select 0 as val, 'f' as var from dual)
    11  select *from t
    12  where t.var = coalesce(:pvar1,:pvar2,:pvar3,:pvar4,t.var);
           VAL V
             1 a
             2 a
             3 b
             4 b
             5 b
             6 c
             7 d
             8 e
             9 e
             0 f
    10 rows selected.
    SQL> exec :pvar4 := 'b';
    PL/SQL procedure successfully completed.
    SQL>  with t as(    select 1 as val, 'a' as var from dual union all
      2       select 2 as val, 'a' as var from dual union all
      3       select 3 as val, 'b' as var from dual union all
      4       select 4 as val, 'b' as var from dual union all
      5       select 5 as val, 'b' as var from dual union all
      6       select 6 as val, 'c' as var from dual union all
      7       select 7 as val, 'd' as var from dual union all
      8       select 8 as val, 'e' as var from dual union all
      9       select 9 as val, 'e' as var from dual union all
    10       select 0 as val, 'f' as var from dual)
    11   select *from t
    12   where t.var = coalesce(:pvar1,:pvar2,:pvar3,:pvar4,t.var);
           VAL V
             3 b
             4 b
             5 b
    Message was edited by:
            jeneesh
    I did mistake. Follow Dave's post                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Using NULL in Condition Object

    Is there are way to use the value NULL in the Condition object. For example, the following does not work because I really need "U_PLS_SysU IS NULL" for my query to work:
    conditions = new SAPbouiCOM.Conditions();
    condition = conditions.Add();
    condition.Alias = "U_PLS_SysU";
    condition.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
    condition.CondVal = "NULL";
    This statement gets interpreted literally of course and does not return the correct rows. Is there a workaround?
    Thanks

    It´s just a guess, but... have you tried something like an SQL injection?
    Some trick like:
    conditions = new SAPbouiCOM.Conditions();
    condition = conditions.Add();
    condition.Alias = "U_PLS_SysU";
    condition.Operation = SAPbouiCOM.BoConditionOperation.co_EQUAL;
    condition.CondVal = "   '' OR U_PLS_SysU IS NULL";
    //There are 2 single quotes begore OR word
    If it was well designed it shouldn´t work, but you never know...
    Regards,
    Ibai Peñ

  • Operator="in" , Fetch Xml, MS CRM 2011

    hi,
    i have a guid's string array.
    ex: string[] recordGuids;
    i want to use this in fetchxml by using condition operator "in".
    i have tried this below code but no success ("The remote server returned an error: NotFound.").
    var fetchXml = @"<fetch mapping='logical'>
    <entity name='annotation'>
    <attribute name='filename' />
    <filter>
    <condition attribute='objectid' operator='in'>"+
    "<value>" + recordGuids + "</value>" +
    "</condition>"+
    "</filter>"+
    "</entity>"+
    "</fetch>";
    when i debug and check the query, that was something like this( which is wrong query ).
    <fetch mapping='logical'>
    <entity name='annotation'>
    <attribute name='filename' />
    <filter>
    <condition attribute='objectid' operator='in'> <value>System.String[]</value> </condition> </filter> </entity></fetch>
    can anyone give me an idea to retrieve set of records by using condition operator "in" by passing string array.
    Thanks and Regards. Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    hi Can you please try below code,
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" +
    "<entity name='new_pledge'>" +
    "<attribute name='new_name' />" +
    "<attribute name='new_pledgeid' />" +
    "<attribute name='new_marketvalue' />" +
    "<order attribute='new_name' descending='false' />" +
    "<filter type='or'>" +
    "<condition attribute='new_pledgeid' operator='eq' value='";
    for(var i = 1; i<= Pledgeid.length;i++)
    fetchXml += "<value>" + Pledgeid[i] + "</value>";
    fetchXml += "' />"+
    "</filter>" +
    "</entity>" +
    "</fetch>";
    var layoutXml = "<grid name='resultset' object='1' jump='name' select='1' icon='1' preview='1'>" +
    "<row name='result' id='new_pledgeid'>" +
    "<cell name='new_name' width='300' />" +
    "<cell name='new_pledgeid' width='100' />" +
    "<cell name='new_marketvalue' width='100' />" +
    // "<cell name='new_by_months' width='100' />" +
    "</row>" +
    "</grid>";
    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

Maybe you are looking for

  • Mod/PlSql Report without 'save as' menu and with print control

    I have to design a secure report. They want me to design it in a secure way so that people can see their special data on the screen but can not have a 'Save as' menu, and plus people can print their reports only three times in a month, no more. I hav

  • Issue with OBIEE 11.1.1.5.0 Installation on Windows 2008 64-bit machine

    Hi I'm following the below steps to install OBIEE 11.1.1.5.0 Installation on Windows 2008 64-bit machine. However the installation is unsuccessful as it fails at the "Domain Creation" step. It would be very helpful and greatly appreciated if any work

  • Version 10.3.1.1784

    Hi, Since yesterday, I'm trying to download the new available 10.3.1.1784 version (746MB). However while installing, around 436 MB, it shows some error & the download starts once again. Please help. Kartik

  • Click the button of Message box through code.

    Hi, Is there any way to click the Message Box button  through code? Is there any way to restrict the MessageBox popup? The requirement is, i need to open the SalesOrder form in FindMode,  Since there are other addons which will add some values in the

  • Blind Vias in Ultiboard v9 and v10

    I have been dealing with EWB for some months now on a problem with placing blind vias into Ultiboard designs.  They have been "working on it" without any good solutions.  I would like to see if there are other users with this issue.  For grins I woul