views:

99

answers:

1
+2  Q: 

Syntax error in Ax

 static void Job(Args _args) 
 { 
    int number=10;
    do
     {
        print (strfmt("current number = %1", number));
        number --;
     }while (number != 0)  
  }

This is a job just for testing do-while in X++ , and I get a "syntax error" in the last '}'

I'm new to Dynamics AX and to X++, so I don't know if there's something I'm missing, but I'd say it should work.

-----[EDIT]-----
second part of the question was moved to a separate question

+3  A: 

As in many C style languages, the DO WHILE loop does require a semicolon at the end of the while test:

http://msdn.microsoft.com/en-us/library/aa842320.aspx

SYNTAX

do
{ statement }
while
( expression ) ;

Fixed code:

static void Job(Args _args) 
{ 
  int number=10;
  do
   {
      print (strfmt("current number = %1", number));
      number --;
   }while (number != 0); <-- semicolon required here
}

The reason the error doesn't occur until the final brace is that the compiler doesn't realize there's something missing until that point in the code.

Adam Davis
thank you! +1, now, how am i supposed to notice other errors in more complex statements further on ? any tips to add ?
MarceloRamires
http://stackoverflow.com/search?q=general+code+debuggin+techniques for one.
Adam Davis
The second part of your question is better left as a separate question, so I created one for it here: http://stackoverflow.com/questions/2001069/understanding-compiler-error-messages
Adam Davis
i'll do another one myself, i'm not talking about any language, i'm talking about x++ debugging in dynamics ax, i don't want generic techniques, i want tools in dynamics, or being told that there are none and that i should give up trying to find an easier way and just know every error by heart.
MarceloRamires
question made, already updated this one, check out in the "separate question" link in the end.
MarceloRamires