Have an idea?

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

Creating a for loop (Perl)

I need to create a for loop in perl. Below is what I have. Can someone please help me out with what I am doing wrong?

[% Begin Unverified Perl
    my $GetPhoneNum = GETVALUE("LastLoopNum");

    for (my $iter = 1; $iter <= $GetPhoneNum; $iter++){
        IF ($iter == 1){
            SETVALUE("Value1", "PhoneBrandsScreened.1");
        }
        if ($iter == 2){
            SETVALUE("Value2", "PhoneBrandsScreened.2");
        }
        if ($iter == 3){
            SETVALUE("Value3", "PhoneBrandsScreened.3");
        }
        if ($iter == 4){
            SETVALUE("Value4", "PhoneBrandsScreened.4");
        }
        if ($iter == 5){
            SETVALUE("Value5", "PhoneBrandsScreened.5");
        }
        if ($iter == 6){
            SETVALUE("Value6", "PhoneBrandsScreened.6");
        }
    }
End Unverified %]}
asked Jul 8, 2015 by ChrisD

1 Answer

+1 vote
Try
[% Begin Unverified Perl

my $GetPhoneNum = VALUE("LastLoopNum");
for (my $iter = 1; $iter <= $GetPhoneNum; $iter++)
{
  SETVALUE("Value" . $iter, "PhoneBrandsScreened." . $iter);
}

End Unverified %]
answered Jul 8, 2015 by Mike Lodder Gold (23,410 points)
Thanks Mike! This is what I needed. All I changed was to set the value.

SETVALUE("Value" . $iter, VALUE("PhoneBrandsScreened." . $iter));

Thanks again!
...