Consider this:
SWITCH ($mode)
{
MODE1
{
}
MODE2
{
}
MODE3
{
}
}
Can I directly call the code under MODE1, MODE2, or MODE3 without executing the entire SWITCH statement?
I have a situation where MODE3 can only run if MODE2 has been completed, and MODE2 can only run if MODE1 has been completed. I have moved all the code for each MODE into a separate function. However, the logic to determine if previous modes have completed is growing in size, duplicates code, and is confusing.
For instance:
SWITCH ($mode)
{
MODE1
{
DoMode1
if (!Mode1Complete) { Exit }
}
MODE2
{
if (!Mode1Complete) { DoMode1 }
if (!Mode1Complete) { Exit }
DoMode2
}
MODE3
{
if (!Mode2Complete)
{
if (!Mode1Complete)
{
DoMode1
if (!Mode1Complete) { Exit }
DoMode2
if (!Mode2Complete) { Exit }
}
else
{
DoMode2
if (!Mode2Complete) { Exit }
}
}
DoMode3
}
}
You can see how this will get complicated real quick!
What I want to do is this:
SWITCH ($mode)
{
MODE1
{
DoMode1
If (!Mode1Complete) { Exit }
}
MODE2
{
if (!Mode1Complete)
{
#Call MODE1
}
if (!Mode1Complete) { Exit }
DoMode2
}
MODE3
{
if (!Mode2Complete)
{
#Call MODE2
}
if (!Mode2Complete) { Exit }
DoMode3
}
}
Please note "MODEx" is just an example. The actual conditions will not be in numerical order like this. They will be different words.
Any ideas how to make this happen?
switch, and tryifstatements, refactored functions, etc. for full flow control.