October 11, 2026โ€ข5 min read

Syntax Rules: One Missing Semicolon Stops the Program

You wrote a few lines and the program already refuses to run? Most of the time the logic is fine, and one character is missing or in the wrong place.

Read in Indonesian

If you have just started learning to code, the first sight you meet is probably not a program running smoothly, but a screen full of red text. The computer is not angry; it simply does not understand what you wrote. That is where syntax, the rules of grammar, takes its role.

This part frustrates beginners, even though the problem is not about logic. Most of the time one character is missing or in the wrong place. Let's take the syntax rules apart one by one. Each rule comes with code that actually runs.

Key takeaways

  • Syntax is the grammar that decides which code shapes are valid, separate from semantics, which decides what the code means.
  • Statement terminators, indentation, and letter case are all syntax rules that differ between languages.
  • A name (identifier) cannot use a language keyword, and cannot start with a digit.
  • Errors fall into three groups: syntax errors, runtime errors, and logic errors, which are the hardest to trace.

Grammar First, Meaning Second

Syntax is the grammar of a programming language: the shapes and orderings of text that count as valid. If you already know the term, skip this section. Its opposite is semantics, the meaning of the text that already passed as valid. The two are different, and the difference matters first.

Simply put, your code is read in two stages. First tokenizing: text is cut into meaningful units such as names, numbers, and symbols. Second parsing: those units are assembled according to the language's grammar. The moment the grammar is violated, the process stops right there and out comes a syntax error.

A syntax rule is only about shape. A program with a valid shape does not necessarily do what you want; that is the business of semantics.

The easiest example of grammar at work is the statement terminator, and that is the next topic.

The Semicolon: One Character That Makes the Compiler Rage

Many languages mark the end of a statement with a semicolon. C, C++, Java, and JavaScript all belong to this family. The code below intends to multiply the price by the quantity:

C
#include <stdio.h>

int main(void) {
    int harga = 20000;
    int jumlah = 3;
    int total = harga * jumlah;
    printf("total bayar: %d\n", total);
    return 0;
}

Run it through gcc, and the result is:

TEXT
total bayar: 60000

Now delete one semicolon on the line int total = harga * jumlah. The compile process stops at once, and the compiler points at the location of the problem:

TEXT
error: expected ',' or ';' before 'printf'

Notice what is not being complained about: the line that lost its semicolon. The complaint lands on the line after it. The compiler only realizes something is odd when it reaches printf and the previous line was never closed. If you wonder why the error points at a line that looks correct, remember this habit.

Python works another way. There, the end of the line (a newline) is marker enough, so semicolons are optional. What decides the structure instead is indentation. That is why this topic needs its own section.

Braces or Indentation?

In C, Java, and JavaScript, code blocks are bounded by braces { }. Whether you indent or push everything to the left margin, the program stays valid as long as the braces balance. Python is the opposite: indentation is not decoration, but part of syntax you cannot bargain with.

PYTHON
total_belanja = 150000

if total_belanja > 100000:
    print("dapat diskon 10%")
    print("total bayar:", int(total_belanja * 0.9))
print("terima kasih sudah berbelanja")

Run it, and the result is:

TEXT
dapat diskon 10%
total bayar: 135000
terima kasih sudah berbelanja

Now delete the indentation on the line print("dapat diskon 10%"):

TEXT
IndentationError: expected an indented block after 'if' statement on line 3

There is a more dangerous version: valid indentation, in the wrong place.

PYTHON
total_belanja = 50000

if total_belanja > 100000:
    print("dapat diskon 10%")
    print("terima kasih sudah berbelanja")

If you run it, the screen stays empty ๐Ÿ˜…. The number of statements matches the correct version, but the line print("terima kasih sudah berbelanja") moved inside the if block. That means the sentence only prints when the discount applies, though the intent was to print it every time. There it is, the slipperiest kind of error: no message at all, and the meaning has already shifted.

So indentation in Python is syntax, not a writing style. The shape question is settled; now we move to naming, and here letter case joins in.

Letter Case and the Names You Are Allowed to Use

Some languages are case-sensitive, meaning they distinguish uppercase from lowercase. Python is one of them:

PYTHON
Total = 10
print(total)

Output:

TEXT
NameError: name 'total' is not defined. Did you mean: 'Total'?

Total and total count as two different containers. Inside one program you are free to use both, which also means typos are easy ๐Ÿ˜„ whenever your naming is not consistent.

Some languages are case-insensitive. SQLite is one; table names, column names, and keywords ignore case:

PYTHON
import sqlite3

conn = sqlite3.connect(":memory:")
cur = conn.cursor()
cur.execute("create TABLE laporan (total_belanja INTEGER);")
cur.execute("insert into LAPORAN values (150000);")
print(cur.execute("select TOTAL_BELANJA from Laporan;").fetchone())

Output:

TEXT
(150000,)

You wrote create in lowercase, TABLE in uppercase, LAPORAN in all caps, and it still runs. In Python, by contrast, letter case is non-negotiable.

Beyond case, there are two other limits on the names you invent (identifier). Language keywords cannot be used as names, and a name cannot start with a digit:

PYTHON
class = "matematika"

โ†’ SyntaxError: invalid syntax

PYTHON
2total = 5

โ†’ SyntaxError: invalid decimal literal

Words like class, if, and for are already "reserved" for the language, so pick another name, such as kategori, total_belanja, or jumlah_data. Naming is in your hands now; the next question is, what is the difference between a statement and an expression?

Statements and Expressions: What's the Difference?

A statement is a complete command that performs an action. An expression is a piece of code that produces a value once evaluated. The line total_belanja = 150000 is a statement: it tells the computer to store something. Meanwhile total_belanja >= 100000 is an expression: it is only a value, and you can use or print that value:

PYTHON
total_belanja = 150000
print(total_belanja >= 100000)
TEXT
True

In JavaScript the split is the same:

JS
const total_belanja = 150000;
console.log(total_belanja >= 100000);
console.log("total bayar: " + total_belanja * 0.9);
TEXT
true
total bayar: 135000

Look at the last line: total_belanja * 0.9 evaluates to 135000, and only then gets joined into the text. The expression is computed first, and the statement carries the result to the screen. This split will come up constantly, especially when you read an error message. Because shape and meaning can be tested separately, the kinds of errors can be grouped too.

Valid Syntax, Running Program, Wrong Result

Now the part most useful for debugging: recognizing three kinds of error. All three appear at different times, so their clues differ too.

Syntax error comes earliest. The code never runs because its shape violates the grammar, like the missing semicolon in C above. The tool tells you the line and the character it suspects.

Runtime error shows up when the code is already valid and starts running, but something breaks mid-process. Opening a file that does not exist, or dividing a number by zero, are two examples. The code passes parsing, then stops during execution.

Logic error is the quietest. The program runs to completion with no message at all, but the result is wrong. Look at this snippet:

PYTHON
harga = 20000
jumlah = 3
total = harga * jumlah / 100
print("total bayar:", total)

Output:

TEXT
total bayar: 600.0

The syntax is perfect, nothing stops, but a stray / 100 makes the total 100 times smaller than it should be. A compiler and an interpreter cannot catch this kind; only you know that 60000 was the intended number. That is why mastering syntax is only the first step.

If you can now tell a wrong shape from a wrong meaning, error messages stop being a source of panic and start being a clue. Next, try reading the four earlier articles in this series with fresh eyes: every example there obeys the rules you just learned. Happy tinkering, and may your red screens grow rarer! ๐Ÿ‘‹

Just landed in this series? Start from Programming Fundamentals, where the other concepts in the series are covered one by one.

Get better at shipping code.

Join the other developers getting tech updates, tips, and relaxed tutorials in their inbox every week.

Stay in the loop

Tech updates, coding tips, and relaxed insights straight to your inbox every week.

No spam. Unsubscribe anytime.

Read next

See all
Struktur DataWhat a Linked List Actually Is

A linked list is a linear chain of nodes, each holding data and a pointer to the next node. Here is what that chain looks like, what it costs next to an array, and the same minimal implementation in Java, Python, and JavaScript.

For developers who learn by struggling

ยฉ 2026 Inva.dev.