Syntax

Syntax is the set of rules that defines how code must be written in a programming language.

It determines the correct structure and format of instructions.

Why syntax is important

Computers are strict.

If code does not follow the correct syntax:

  • The program will not run
  • An error will appear
  • The compiler or interpreter will stop execution

Even small mistakes can break a program.

Example of correct syntax

if (age >= 18) { print("Adult") }

This follows proper structure:

  • Parentheses
  • Curly braces
  • Correct keyword usage

Example of incorrect syntax

if age >= 18 print("Adult")

This may cause a syntax error in many languages because required symbols are missing.

Syntax vs Logic

  • Syntax error → Code is written incorrectly
  • Logical error → Code runs, but produces the wrong result

Example of logical error:

return a - b

If you intended addition, the syntax is correct — but the logic is wrong.

Syntax depends on the language

Different languages have different syntax rules.

For example:

 

Python:

if age >= 18: print("Adult")

JavaScript:

if (age >= 18) { console.log("Adult"); }

Same logic — different syntax.

Why learning syntax matters

Understanding syntax helps you:

  • Avoid errors
  • Write clean code
  • Read other people’s programs
  • Learn new languages faster

Syntax is the foundation of writing valid code.

Simple example

Think of syntax like grammar in a language. If a sentence is written incorrectly, it becomes confusing or meaningless. Programming works the same way.

Related terms

Source

Simplified from general programming documentation and Wikipedia.

Nach oben scrollen