switch, case etc.

 

Hi 


would like to know if with switch function i can use a range instead of a precise value


switch(i)
     {
      case 1:
         res=i;break;
      default:
         res="default";break;
      case 2:
         res=i;break;
      case 3:
         res=i;break;
     }
   Print(res);

like this


switch(i)
     {
      case 1<5:
         res=i;break;
      default:
         res="default";break;
      case 5<10:
         res=i;break;
      case 10<15 :
         res=i;break;
     }
   Print(res);


ora i have to use if

if(0<x<5){



}else if(5<x<10){

}

//etc
 

Neither this "case 1<5:" (it might always be 1)

nor this "if(0<x<5)" is working in MQL4/5 - just place the cursor above switch and press F1 and start reading..

 
florenceale:

would like to know if with switch function i can use a range instead of a precise value


The documentation page for switch is helpful.

https://www.mql5.com/en/docs/basis/operators/switch

- Jack

Documentation on MQL5: Language Basics / Operators / Switch Operator
Documentation on MQL5: Language Basics / Operators / Switch Operator
  • www.mql5.com
can be marked with an integer constant, a literal constant or a constant expression. The constant expression can't contain variables or function calls. Expression of the variant...
 
Jack Thomas:


The documentation page for switch is helpful.

https://www.mql5.com/en/docs/basis/operators/switch

- Jack


i checked this page before writing here, but it doesnt show the example of a range. 


i know how to do with if, but i wanted to know if i can do also with switch/case

 
florenceale: i checked this page before writing here, but it doesnt show the example of a range.
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
         res=i;break;
 
Carl Schreiber: nor this "if(0<x<5)" is working in MQL4/5 - just place the cursor above switch and press F1 and start reading..
True = 1 and false = 0 so you get
if( 3 < 2 < 1 )
if( false < 1 )
if(     0 < 1 )
if(     true  )
if( 3 > 2 > 1 )
iftrue > 1 )
if(     1 > 1 )
if(     false )