illegal else without matching if

 

Hello everybody,

How come I am getting this error?

void ACCOUNTS()
  {
   int Value=0,
       Orders=0;
   double TicketValue[],
          test=0;

   if(OrderSelect(Orders,SELECT_BY_POS)==true)
      TicketValue[Value]=OrderProfit(); Orders++;
   test=TicketValue[Value];Value++;
   else  // illegal else without matching if
      Print(GetLastError());

  }

If I do this the error goes away.

   double TicketValue[],
          test=0;
   int Value=0,
       Orders=0;

   if(OrderSelect(Orders,SELECT_BY_POS)==true)
      TicketValue[Value]=OrderProfit(); Orders++;
      test=TicketValue[Value];Value++;
 
   if(OrderSelect(Orders,SELECT_BY_POS)==true)
      TicketValue[Value]=OrderProfit();

   else
      Print(GetLastError());

  }
 
GrumpyDuckMan :

Hello everybody,

How come I am getting this error?

If I do this the error goes away.

 void ACCOUNTS()
  {
   int Value= 0 ,
       Orders= 0 ;
   double TicketValue[],
          test= 0 ;

   if ( OrderSelect (Orders, SELECT_BY_POS )== true )
     {
      TicketValue[Value]= OrderProfit (); Orders++;
      test=TicketValue[Value];Value++;
     }
   else    // illegal else without matching if 
       Print ( GetLastError ());

  }

If the next processing of 'if line' is multiple, it must be enclosed in { }.

If it does not enclose, an error occurs because the second line is regarded as a process unrelated to 'if line' and the relationship between if and else is disconnected.

By the way, Orders ++ and Value ++ are reset at the next call, so it is meaningless in the above example.

 
Naguisa Unada:

If the next processing of 'if line' is multiple, it must be enclosed in { }.

If it does not enclose, an error occurs because the second line is regarded as a process unrelated to 'if line' and the relationship between if and else is disconnected.

By the way, Orders ++ and Value ++ are reset at the next call, so it is meaningless in the above example.

Hello,

Thank you for your response.  I will try again and post anything new...I am just a little confused atm.

 
Your code. The formate of an if statement is if(condition) statement [else statement]
   if(OrderSelect(Orders,SELECT_BY_POS)==true)      // If
      TicketValue[Value]=OrderProfit(); Orders++;   // Statement1; Statement2; IF is over.
   test=TicketValue[Value];Value++;                 // Statement3; statement4;
   else                                             // illegal else without matching if, Of course.
      Print(GetLastError());

A statement is one line terminated by a semicolon, or multiple statements enclosed in braces.
   if(OrderSelect(Orders,SELECT_BY_POS)==true)      // If
     {                                              // \ Start of a statement(s.)
      TicketValue[Value]=OrderProfit(); Orders++;   //  \
      test=TicketValue[Value];Value++;              //  /
     }                                              // / End of statement(s,) the IF is over.
   else                                             // Matching else 
      Print(GetLastError());