Syntax Error
A syntax error is a mistake in a computer program's code that violates the rules of the programming language's grammar, preventing the program from being compiled or run. These are like spelling or grammatical errors in a human language, and they can include things like missing punctuation, incorrect use of keywords, or unbalanced brackets.
How it happens
Grammar violation: Every programming language has a set of rules for how code must be structured, which is known as its syntax.
Compiler/interpreter error: When a computer's compiler or interpreter encounters a statement that doesn't follow these rules, it flags it as a syntax error.
Program failure: The program will not run at all until the syntax error is corrected.
Examples of syntax errors
Missing punctuation: Forgetting a semicolon at the end of a statement in languages like Java.
Unbalanced parentheses: Using an opening parenthesis without a corresponding closing one.
Mismatched quotes: Forgetting to close a quotation mark for a text string.
Incorrect keywords: Misspelling a command, such as writing publc instead of public.
Indentation errors: Incorrectly using spaces or tabs to structure code blocks in languages like Python.