Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

How to add multiple if conditions?

Begin Unverified Perl
 if (GETVALUE('A4') < 15) {
    SETVALUE('A4Grp', 1);
    return 1 == 1;
}
else if (GETVALUE('A4')>=15 GETVALUE('A4')< 19) {
    SETVALUE('A4Grp', 2);
    return 1 == 1;
}
else if (GETVALUE('A4')>=20 GETVALUE('A4')< 24) {
    SETVALUE('A4Grp', 3);
    return 1 == 1;
}
End Unverified

this syntax create sawtooth error #132
related to an answer for: Can auto code?
asked Jun 16 by raaamuz (360 points)

1 Answer

0 votes
Try this ...
[%Begin Unverified Perl

 my $a=0;

 if (GETVALUE("A4")<15)
  {
   SETVALUE("A4Grp",1);
   return $a=1;
  }
 elsif (GETVALUE("A4")>=15 && GETVALUE("A4")<19)
  {
   SETVALUE("A4Grp",2);
   return $a=1;
  }
 elsif (GETVALUE("A4")>=20 && GETVALUE("A4")<24)
  {
   SETVALUE("A4Grp",3);
   return $a=1;
  }
  
End Unverified%]

*You did not have the [%%] around the Perl Script.
*Change single quotes to double quotes.
*Insert "&&" in your conditions.
*Define a variable  like $a and return that value.
*Correct the syntax on your "else if" to "elsif"
answered Jun 16 by Paul Moon Platinum (75,480 points)
edited Jun 16 by Paul Moon
...