3. Syntax errors
Syntax error is when a grammatical rule of the computer language is broken
Example : misspelling
The simplest and most-often made mistake is to mistype a keyword for example
pint x
instead of
print x
where the 'r' is missing.
Example: missing end of statement marker
Many languages insist on a symbol to mark the end of a statement for example
print x
instead of
print x;
where a semi-colon is missing in this particular language
Example: missing bracket
This one can be quite tricky to spot as paired brackets can be many lines of code apart. For example a function needs to have its code enclosed in curly brackets { .. }, like this
function this_function() { print x do something do something do something function nextOne() { ... }
Can you spot that the first function does not have an ending curly bracket?
The best way to help reduce this kind of problem is to make careful use of indenting in your source code, then the missing bracket is easier to spot.
Challenge see if you can find out one extra fact on this topic that we haven't already told you
Click on this link: Correcting syntax errors