Has anyone run into problems with nested switch statement? Do they really work in EFS? I am discovering that EFS is bypassing the inner switch and executing statements regardless of CASE in the inner Switch block. Also, am I understanding correctly that variables declared at the top of EFS outside of preMain are global within that EFS and its value gets retained with main()'s each iteration? Please help. Thanks.
Announcement
Collapse
No announcement yet.
Nested Switch statements
Collapse
X
-
Hello z11,
I'm not having any problems with nested switch statements. Check out the code below and see if there are any fundamental differences with your nested switch statement. Do you have all the necessary break statements in place? When you run this code, open your formula output window to see the results. When you go to edit studies to change the formula parameters, enter A, B or C for Category and 1, 2 or 3 for Number.
PHP Code:function preMain() {
setPriceStudy(true);
setStudyTitle("test");
setCursorLabelName("test");
}
debugClear();
function main(Category, Number) {
if (getCurrentBarIndex() != -1) return;
switch (Category){
case "A" :
switch (Number){
case 1 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 2 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 3 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
default : debugPrintln("No valid Number selection");
}
break;
case "B" :
switch (Number){
case 1 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 2 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 3 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
default : debugPrintln("No valid Number selection");
}
break;
case "C" :
switch (Number){
case 1 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 2 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
case 3 :
debugPrintln("Category: " + Category + " Number: " + Number);
break;
default : debugPrintln("No valid Number selection");
}
break;
default : debugPrintln("No valid Category or Number selection");
}
return;
}
Jason K.
Project Manager
eSignal - an Interactive Data company
EFS KnowledgeBase
JavaScript for EFS Video Series
EFS Beginner Tutorial Series
EFS Glossary
Custom EFS Development Policy
New User Orientation
Comment
Comment