Styler formatting

 

Good morning
I have a problem with the styler accessible in tools => Styler
It seems not to recognize else if

it transforms them into else, then if

Here is some test code

 int value = 5 ;

 if ( value == 1 ) {
    Print( "Value is 1" );
} else if ( value == 2 ) {
    Print( "Value is 2" );
} else if ( value == 3 ) {
    Print( "Value is 3" );
} else if ( value == 4 ) {
    Print( "Value is 4" );
} else {
    Print( "Value is not 1, 2, 3, or 4" );
}

and once passed through the styler

 int value = 5 ;

 if ( value == 1 )
  {
   Print( "Value is 1" );
  }
 else 
   if ( value == 2 )
     {
      Print( "Value is 2" );
     }
   else 
       if ( value == 3 )
        {
         Print( "Value is 3" );
        }
       else 
         if ( value == 4 )
           {
            Print( "Value is 4" );
           }
         else 
           {
            Print( "Value is not 1, 2, 3, or 4" );
           }

This bothers me.... Can we do something to keep the else ifs?

THANKS


 
Gerard Willia G J B M Dinh Sy: I have a problem with the styler accessible in tools => Styler

It seems not to recognize else if

it transforms them into else, then if

Here is some test code

and once passed through the styler

This bothers me.... Can we do something to keep the else ifs?

THANKS

There is nothing wrong with that. In fact, it is showing you the correct levels of the code.

In this case, it would be much better to use a "switch" operator instead of the multiple "if".

Documentation on MQL5: Language Basics / Operators / Switch Operator
Documentation on MQL5: Language Basics / Operators / Switch Operator
  • www.mql5.com
Switch Operator - Operators - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:
There is nothing wrong with that

Hello.

I didn't say it was wrong, I said it bothered me, because I like my "else if" and seeing them split into "else" then "if" disturbs and disturbs me.


So obviously, no way to keep my else if with the styler?

 

I think I found
In tools => options, styler tab choose "google" for example and the "else if" are kept.
Formatting on anything else isn't quite how I want it, but it will be fine


int value = 5;

if (value == 1) {
   Print("Value is 1");
} else if (value == 2) {
   Print("Value is 2");
} else if (value == 3) {
   Print("Value is 3");
} else if (value == 4) {
   Print("Value is 4");
} else {
   Print("Value is not 1, 2, 3, or 4");
}
Reason: