switch case does not work with vars

Discussion of Inner Space

Moderators: Lavish Software Team, Moderators

Post Reply
bountycode
Non-Subscriber
Posts: 22
Joined: Mon Jul 12, 2004 8:27 am

switch case does not work with vars

Post by bountycode » Sat Oct 15, 2005 2:11 pm

how do you pass a variable to the case statement?

this works

declare vVal string one

Switch "${vVal}"
{
case one
echo val is one
break
Default
echo "can't find vaule"
break
}

but this won't work for some reason

declare vTest string one
declare vVal string one

Switch "${vVal}"
{
case ${vTest}
echo val is one
break
Default
echo "can't find vaule"
break
}


btw where should I be posting LavishScript questions I did not see a LavishScript Forum category

Lax
Owner
Posts: 6634
Joined: Fri Jun 18, 2004 6:08 pm

Post by Lax » Sat Oct 15, 2005 3:46 pm

Here is fine.

You can't use a variable in a case. A switch gives you speed by using a predefined table of conditions and the code to execute for each. If you start using variables as cases, there can no longer be such optimization, and you should just use if statements.

bountycode
Non-Subscriber
Posts: 22
Joined: Mon Jul 12, 2004 8:27 am

Post by bountycode » Sat Oct 15, 2005 9:05 pm

Thanks for the prompt responses and a great software product :)

Post Reply