Separating statements

A programming language will separate statements by defining where a statement ends. If the language can figure out where one statement ends, it also knows that what comes after it must be the beginning of another statement.

Languages have different ways to define this. If we compare how different languages terminate statements, we’ll see that we have three main ways for it to be done. Many languages will terminate a statement by inserting a new line. This means that, in general, every line is a single statement if it isn’t a compound statement, since it will need to be handled uniquely.

Another popular way to terminate statements is by using a semicolon, ;. For languages that use this technique, we can have several statements on a single line. The language knows that a statement ends as soon as it sees a semicolon.

A third variant is to use a period . instead of a semicolon. Apart from that, it works the same way as when a semicolon is used, meaning we can have more than one statement on a single line.

Get hands-on with 1400+ tech skills courses.