Which Programming Languages Use Semicolons? We Counted 4,437 of Them

The short answer: C, C++, Java, C# and PHP need a semicolon at the end of almost every statement. JavaScript and TypeScript use them but can insert most of them for you. Python, Ruby, Go, Swift and Kotlin do not need them, because a new line ends the statement. Rust gives the semicolon a meaning: leave it off the last line of a block and that line becomes the block's value. In our 1,340 code snippets, C had 38 semicolons per 1,000 characters, more than any other symbol, and Python had none.
Key Findings
- •
4,437 semicolons in 1,340 snippets, 21.5 per 1,000 non-space characters across nine languages.
- •
In C, one character in 26 is a semicolon. It is C's most common symbol, ahead of both parentheses (712 against 574 each).
- •
Python: zero. Not one semicolon in 140 Python snippets.
- •
Rust ends 38% of blocks without one, because the last expression is the value the block returns.
- •
All 150 JavaScript snippets use semicolons, even though the language can insert them automatically.
Source: TurboType analysis of 1,340 code snippets in nine languages, 206,028 non-space characters, November 2026.
1. Semicolons in Every Major Language
Languages fall into four groups: semicolons required, optional, not used, or meaningful. Here is where the common ones sit.
| Language | Semicolons | What happens without one |
|---|---|---|
| C, C++ | Required after statements and declarations | Compile error, usually reported on the next line |
| Java, C# | Required after statements | Compile error |
| PHP | Required after statements | Parse error, except the last statement before a closing ?> tag |
| JavaScript, TypeScript | Optional in most places | Automatic semicolon insertion adds them, with a few traps |
| Rust | Required after statements; meaningful at the end of a block | The last expression becomes the block's return value |
| Go | Inserted by the compiler | Nothing; you only write them in for loop headers |
| Python | Not used; allowed between statements on one line | Nothing; a new line ends the statement |
| Ruby, Swift, Kotlin | Optional, rarely written | Nothing; a new line ends the statement |
| CSS | Separates declarations | That declaration and the next are ignored; optional after the last one in a block |
| SQL | Ends a statement | Needed between statements in most tools and scripts |
2. How Many Semicolons Each Language Uses
We counted every semicolon in 1,340 snippets from our practice library, after removing comments and the contents of strings so that only semicolons in code were counted.
| Language | Semicolons | Per 1,000 chars | Per 100 lines | Rank among symbols |
|---|---|---|---|---|
| C | 712 | 38.3 | 67.1 | 1st |
| C++ | 714 | 29.1 | 64.9 | 2nd, after the colon |
| JavaScript | 571 | 26.8 | 59.5 | 4th |
| Rust | 603 | 23.6 | 43.2 | 4th |
| TypeScript | 540 | 20.8 | 48.6 | 2nd, after the colon |
| Java | 480 | 19.9 | 48.0 | 4th |
| PHP | 582 | 19.9 | 48.4 | 5th |
| HTML & CSS | 235 | 15.1 | 26.1 | 8th |
| Python | 0 | 0 | 0 | – |
C leads by a distance. One character in every 26 is a semicolon, and it is the most common symbol in C, ahead of the parentheses. Part of that is the for loop: 38 loops in our C snippets use the classic three-part header, which puts two semicolons in every one.
C++ and TypeScript have the semicolon in second place, behind the colon. In C++ the colon comes from std::; in TypeScript it comes from type annotations, and 61 TypeScript lines are typed members or fields that end in a semicolon, such as name: string;.
3. Why Do Programming Languages Use Semicolons?
A semicolon tells the compiler exactly where one statement ends and the next begins. Without a marker, a parser has to guess whether a line break ends the statement or whether the expression continues on the next line.
The habit is old. ALGOL 60 used semicolons to separate statements, Pascal kept that, and C made the semicolon a terminator that ends every statement. Because C, C++, Java, C#, JavaScript and PHP all borrowed C's syntax, most of the world's code inherited the rule. A terminator has a practical advantage: the code does not depend on line breaks, so you can split a long expression across lines, or put two statements on one, without changing its meaning.
Newer languages mostly decided the line break was enough. Python, Ruby, Swift and Kotlin end a statement at the end of the line unless the expression is clearly unfinished. Go is a middle path: the grammar still uses semicolons, but the compiler inserts them automatically at line ends, so Go programmers almost never type one.
4. Do You Need Semicolons in JavaScript?
Strictly, no. JavaScript has automatic semicolon insertion (ASI): when a line break would otherwise produce invalid code, the parser inserts a semicolon for you. Most code without semicolons runs exactly as intended. The danger is the cases where the code is still valid without a break, so nothing is inserted:
- •
A line that starts with
(or[.const a = bfollowed by a line starting with(is read as callingbas a function. - •
A line that starts with a backtick. The previous expression is treated as a tag for the template literal.
- •
returnon its own line. A semicolon is inserted straight afterreturn, so the function returnsundefinedand the value on the next line is never reached.
Teams settle this with a style rule rather than memory. Prettier adds semicolons by default, as does the Airbnb style guide; StandardJS leaves them out and relies on lint rules to catch the risky lines. Either works if a tool enforces it.
Our JavaScript and TypeScript snippets are written with semicolons throughout: all 150 JavaScript snippets contain them. The only lines before a closing brace that end without one are object properties and enum members, which take a comma or nothing at all.
5. Rust: The Semicolon That Changes the Value
Rust treats almost everything as an expression, and the semicolon is what turns an expression into a statement that discards its value. The last expression in a block, written without a semicolon, becomes the value of the block. That is how most Rust functions return:
fn area(w: f64, h: f64) -> f64 { w * h }
Add a semicolon after w * h and the block returns (), the empty value, so the compiler reports mismatched types and suggests removing the semicolon. It is one of the first errors every Rust learner meets.
Our data shows the difference clearly. In C, C++, Java and PHP, 99% to 100% of the lines just before a closing brace end with a semicolon. In Rust it is 62%: 68 of 181 blocks end with a bare expression such as x * y, Ok(x / y) or values.iter().sum(), which is the value the block hands back.
6. Other Places Semicolons Appear
- •
For loops.
for (int i = 0; i < n; i++)uses two semicolons to separate its three parts, in C, C++, Java, JavaScript, PHP and even Go.for (;;)is an infinite loop. - •
After a closing brace in C and C++. Struct, enum and class definitions end with
};, and a do-while loop ends withwhile (...);. Function bodies do not, which is a classic beginner mix-up. Our C snippets have 17 lines ending in};, from type definitions and initializer lists. - •
CSS. Every declaration ends with one, as in
color: red;. 233 of the 235 semicolons in our HTML & CSS snippets are CSS; the other two end HTML entities such as&. - •
Python one-liners. Python allows
x = 1; y = 2on one line, but PEP 8 discourages putting several statements on a line, and our Python snippets never do.
7. Typing the Semicolon
On a QWERTY keyboard the semicolon is the home key of the right little finger, so you can type it without moving your hand. That is lucky, because in C-style languages it is one of the most typed keys of all. In our C snippets the semicolon is 18% of everything the right little finger types.
The common mistakes are rhythm mistakes: forgetting it at the end of a line, or adding one where it does not belong, after a function body or the condition of an if. Many editors now add the semicolon automatically, but typing it as part of the line, rather than as an afterthought, keeps your hands on the home row. Our keystroke analysis shows how much of a programmer's typing lands on that finger.
8. Method and Limits
We analysed 1,340 snippets from TurboType's practice tracks: 150 each in JavaScript, TypeScript, Java, C, C++, PHP, Rust and HTML & CSS, and 140 in Python (ten object-oriented Python snippets were excluded). Comments and the contents of strings were removed before counting. Per-line figures count non-empty lines. The closing-brace test looks at the last line before a line that starts with }, ignoring lines that end in {, } or a comma.
Limits: practice snippets are short, so for loops and declarations are over-represented compared with long functions in production code. The language rules in the first table hold everywhere; the counts describe our sample.
9. Frequently Asked Questions
Which programming languages use semicolons?
C, C++, Java, C# and PHP require a semicolon after almost every statement. JavaScript and TypeScript use them but can insert most of them automatically. Rust requires them after statements and uses their absence to return a value. Python, Ruby, Go, Swift and Kotlin do not need them.
Does Python use semicolons?
No. In Python a new line ends a statement. A semicolon is allowed to put two statements on one line, as in x = 1; y = 2, but the style guide PEP 8 discourages it. Our 140 Python snippets contained no semicolons at all.
Do you need semicolons in JavaScript?
Not strictly. Automatic semicolon insertion adds them where a line break would otherwise be invalid. It fails when a line starts with ( or [ or a backtick, and return on its own line returns undefined. Prettier and the Airbnb style guide add semicolons; StandardJS leaves them out.
Why does Rust sometimes not use a semicolon?
Because the last expression in a Rust block, written without a semicolon, is the value the block returns. Adding a semicolon turns it into a statement and the block returns the empty value (), which usually causes a mismatched types error.
Why do programming languages use semicolons?
A semicolon marks exactly where a statement ends, so the compiler does not have to guess from line breaks. It lets you split one statement across several lines or put several on one line. Most languages that use them inherited the rule from C.
Next Steps:
- Practise semicolon-dense code on the C track until the right pinky hits it without a pause.
- Contrast it with the Rust track, where the last line of a block often has no semicolon.
- Take the 60-second coding typing test and count missed or extra semicolons in your errors.
