Announcement

Collapse
No announcement yet.

Nested Switch statements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Nested Switch statements

    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.

  • #2
    I fixed the nested switch problem by making sure eace case every level ends with break; statement.

    Comment


    • #3
      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(CategoryNumber) {
          if (
      getCurrentBarIndex() != -1) return;

          switch (
      Category){
             case 
      "A" 
                  switch (
      Number){
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     default :  
      debugPrintln("No valid Number selection");
                  }   
                break;
             case 
      "B" 
                  switch (
      Number){
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     default : 
      debugPrintln("No valid Number selection");
                  }   
                break;
             case 
      "C" 
                  switch (
      Number){
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     case 

                        
      debugPrintln("Category: " Category "  Number: " Number);
                        break;
                     default : 
      debugPrintln("No valid Number selection");
                  }   
                break;
             default : 
      debugPrintln("No valid Category or Number selection");
          }   

          return;    

      Any variables declared outside of preMain(), main() or any user defined function are global to the EFS and will retain their values between executions of the EFS.
      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

      Working...
      X