Hi everyone,
Ive been trying to figure this one out for a few days. I have 6 things that i need to be able to toggle between but i need the switch statement to always begin at "case 0". Is it possible to make a switch statement always begin at "case 0" when I execute the command and if so, how can i accomplish this?
this is a base example as ive only been playing around with this for the past couple of days. If i needed case 3 on 1 object, i would need to toggle 4 times. Then say i needed case 0 on a different object, i would need to toggle and go through the rest of the switch statement before it reaches case 0 again. I was just wondering if there was a way that once ive reached the desired case, if the switch statement can be reset so that it begins a case 0 once i need it again.
global proc example()
{
global int $Toggle;
string $selections[] = `ls -sl`;
$Toggle++;
switch ($Toggle)
{
case 0:
for ($each in $selections)
{
do something;
}
break;
case 1:
for ($each in $selections)
{
do something;
}
break;
case 2:
for ($each in $selections)
{
do something;
}
break;
case 3:
for ($each in $selections)
{
do something;
}
break;
case 4:
for ($each in $selections)
{
do something;
}
break;
case 5:
for ($each in $selections)
{
do something;
}
break;
default:
$Toggle = 0;
for ($each in $selections)
{
do something;
}
break;
}
select -r $selections;
}
example();
Why use "toggle"? Don't you know what you want to do with your selection? Why not just run the command you want on your selection?
I'm sorry that I am failing to see what you are trying to do. Also, print statements are a great aid in working through your code.
It your default case you are setting the value to 0, but you immediately increment the value to 1 with the statement "$Toggle++" before the switch statement. I would either set the value to -1 in your default branch, or move the "$Toggle++" after the switch statement.
Can't find what you're looking for? Ask the community or share your knowledge.