Multiple mixed conditions (string and value) using $Ifthen

I posted another question for the multiple numerical conditions. https://newforum.gams.com/t/multiple-conditions-in-ifthen/3524/1 That is helpful!

Now due to the need of the naming system and the modeling scenarios, I have both string and value conditions to set using $ifthen structure. The following example is the trail I fail to activate the display statement with iclone=2 and random=R. Need help to correct the condition and let the display work when the iclone=2 and random=R.

Thanks,
Jia

$ifThen.cl (%iclone%<>1)or(%random%==R)
display a
$endif.cl

Hi zhj0735,

Use $ifthenE for numerical expressions, also see:
https://www.gams.com/mccarlGuide/ifthen_iftheni_ifthene_conditi.htm

This seems to work but I’m not sure if it is the most elegant solution:

$ifThene.cl %iclone%<>1
$ifThen.cl2 %random%==R
display a;
$endif.cl2
$endif.cl

Regards,
GFA

Hi GFA,

Thanks for the answer.

But the nested structure you propose an “AND” logic instead of “OR” logic that I need. Wondering is there any $ifthen or $if options to go with to deal with this problem.

Best

This should work:

$ife %iclone%<>1 $set x yes
$if %random%==R $set x yes
$if %x% == yes display A

Or this:

$ife %iclone%<>1 $goto x
$if %random%==R $goto x

$goto skipx
$label x
display a
* + other statements if u wish
$label skipx

GFA

You can do string comparisons in a compile-time evaluation (e.g. ifThenE) using function sameas:

$ifThenE.cl (%iclone%<>1)or(sameas('%random%','R'))
display a
$endif.cl

Beware that sameas does a case insensitive string compare.

-Michael

Thank you Michael!