Vex : Switch and case syntax?

   1968   2   0
User Avatar
Member
10 posts
Joined: Jan. 2015
Offline
Hello,
I have a basic question, is there a VEX command similar to the

Switch (myVar)
{
case value1 :
do stuff;
break
case value2 :
do stuff;
break
case value3 :
do stuff;
break
}
we used in C ?
I skimmed the help and the forum, couldn't find anything…
Thanks,
Y.
Head of CGTraining - ESMA School, Toulouse -
User Avatar
Member
1834 posts
Joined: Sept. 2015
Offline
There isn't a switch equivalent.

You have to build your own ‘equivalent’.

You could use a series of if conditionals and a ‘master’ variable that indicates when one of those ifs has already been executed e.g.

int If_Already_Executed = 0;
...
...

if( (myVar == 5) && ( If_Already_Executed == 0 ))
{
//Do stuff because of and related to value1
If_Already_Executed = 1;
}
...
...

Or, you could make use of a struc in which a function is called to ‘index’ another function that encapsulates what is to happen for that index value.
Edited by BabaJ - Sept. 19, 2018 11:35:03
User Avatar
Member
10 posts
Joined: Jan. 2015
Offline
I like the straightfowardness of the “AlreadyExecuted” version - will be a good thing to teach to my students. The Struct version goes beyond what's left of both my programming skills and needs, soooo…
Thanks a lot for your answer !
Y.
Head of CGTraining - ESMA School, Toulouse -
  • Quick Links