When writing programs, code should be as legible and error free as possible. Debugging helps keep code free of errors and documenting helps keep code clear enough to read.
syntaxRules governing how to write statements in a programming language. is the spelling and grammar of a programming languageA language used by a programmer to write a piece of software. . Programming languages have rules for spelling, punctuation and grammar, just like the English language. In programming, a syntax errorAn error in a programming language caused by not using the correct syntax. These are normally spelling errors or small grammatical mistakes. occurs when:
there is a spelling mistake
there is a grammatical mistake
Syntax errors will cause a program to crash or not run at all. The programSequences of instructions for a computer. may run until it encounters a syntax error, then it will stop.
Types of syntax error
More than one type of syntax error may exist. There may be:
incorrectly spelled statementThe smallest element of a programming language which expresses an action to be carried out.
incorrectly spelled variableA memory location within a computer program where values are stored.
missing punctuation (quotes, brackets, etc)
Any one or more of these errors may exist in a program, and each will cause the program to crash or not run at all.