views:

151

answers:

2

As said in the book Microsoft Dynamics AX 2009 Programming: Getting Started it´s needed to put semicolons after declarations in x++:

The extra semicolon after the variable declaration is mandatory as long as the first line of code is not a keyword. The semicolon tells the compiler that variable declarations have come to an end. You cannot declare new variables after this semicolon.

(copied directly from the book, unchanged, if needed i´ll remove it)

However, when i remove the semicolon and run the job, there´s absolutely no error or problem:

static void Job1(Args _args)
{
str string1 = "STACKOVERFLOW";
;
print string1;
pause;
}

works just as

static void Job2(Args _args)
{
str string1 = "STACKOVERFLOW";

print string1;
pause;
}

Is it really needed ? should i get used to using it ?

+5  A: 

It's explained rather elegantly here.

A key quote:

"The reason you need that extra semicolon is because the compiler can’t always see where the variable declarations end. If you don’t help a little, it will make a guess. And it’s not very good at guessing."

Shmoopty
i´ve seen you´re not really into x++ and dynamics (based on your questions and answers) did you just search for it? well found!
MarceloRamires
+3  A: 

You only need the semicolon if the body of your code doesn't start with a keyword. In your example, your code starts with print, which is a built in keyword. If you had tried to start you code with: string1+=".COM"; you would receive an error.

Dynamics AX 2009 is the last version of AX that will require the extra semicolon. AX 6.0 should fix this: mfp's two cents: What's up with this semicolon?

Jay Hofacker

related questions