Logout

3.1.1 Define syntax and semantics.

(No Teaching not from syllabus.)

JSR Notes:

Class notes. Note that I'll do these when I get a chance, and that they are intended as reinforcement only; your main source of learning for topic 3 will be the IB textbook, and in-class lectures, and the notes you take during them. Further, your main guidance for what you need to know remains the syllabus statements themselves. 
And, it will take me a while to come up with a good, easy to read formatting routine. Formatting text in an HTML environment is quite different from in a word processor; there are certainly disadvantages, but advantages as well; I just have to find them...

Syntax versus semantics:

Here's an example:

Bad Java syntax but ok semantics - at least four problems:


for(int i = 0 : i < 100; i++)
{
    system.out.println('Hello world')
}  

The compiler will pick up these syntax errors and not completely compile the program until you have corrected them.

Proper Java syntax, but bad semantics:


for(int i = 0 ; i < 100; i--){
    System.out.println("Hello world");
}

The compiler will not pick up the error in intention. This infinite loop will execute, unfortunately.