kai700 Posted September 30, 2014 Report Share Posted September 30, 2014 (edited) Hallo,grundsätzlich verwende ich gerne das Konstrukt: switch (true) { case (a == b): ... case (a == c): ... u.s.w. Scheint es in Mql4 nict zu geben, richtig? Gruss Kai Edited September 30, 2014 by whipsaw code tag eingefügt Quote Link to comment Share on other sites More sharing options...
Rumpel Posted September 30, 2014 Report Share Posted September 30, 2014 Laut Doku schon. http://docs.mql4.com/basis/operators/switch Quote Link to comment Share on other sites More sharing options...
oldschuren Posted October 1, 2014 Report Share Posted October 1, 2014 Nimm doch else if() if(x=='a'){ y=1; } else if (x=='b'){ y=2; z=3; } else if(x=='c'){ y=4; } else Print("ERROR"); http://docs.mql4.com/basis/operators/if Quote Link to comment Share on other sites More sharing options...
kai700 Posted October 2, 2014 Author Report Share Posted October 2, 2014 (edited) Laut Doku schon. http://docs.mql4.com/basis/operators/switch Die Docu kannte ich. Und sie liest sich auch so, dass es nicht gehen dürfte: "The constant expression can't contain variables or function calls. Expression of the switch operator must be of integer type."Jetzt habe ich aber noch mal probiert und folgendes geht. Switch operator ist doch jetzt bool? Das es vorher nicht ging, lag an der Syntax. man muss die Variable jeweils in Hochkomma innerhalb der Klammer. <code> int a = 2; int b = 3; switch(true) { case ('a'=='b'): Print("CASE A == B"); break; case ('a'<='b'): Print("CASE A <= B"); default: Print("default"); break; }</code> PS: Sorry, ich hab mir jetzt zum zweiten mal nen Wolf gesucht, wie die code-tags funktionieren. Ich finds nicht.Gruss kai Edited October 2, 2014 by kai700 Quote Link to comment Share on other sites More sharing options...
kai700 Posted October 2, 2014 Author Report Share Posted October 2, 2014 Nimm doch else if() if(x=='a'){ y=1; } else if (x=='b'){ y=2; z=3; } else if(x=='c'){ y=4; } else Print("ERROR"); http://docs.mql4.com/basis/operators/if Manchmal brauch ich mehr als 3 Bedingungen. Und ich finde switch (true) übersichtlicher. Gruss Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.