Role of SemiColon in various Programming Languages - GeeksforGeeks (2024)

Improve Article

Save Article

  • Difficulty Level :Medium
  • Last Updated :23 Apr, 2020

Semicolon is a punctuation mark (;) indicating a pause, typically between two main clauses, that is more pronounced than that indicated by a comma. In programming, Semicolon symbol plays a vital role. It is used to show the termination of instruction in various programming languages as well, like C, C++, Java, JavaScript and Python.

In this article, let us see the act of Semicolon in different programming languages:

Role of Semicolon in C:


Role of SemiColon in various Programming Languages - GeeksforGeeks (1)

  1. Semicolons are end statements in C.
  2. The Semicolon tells that the current statement has been terminated and other statements following are new statements.
  3. Usage of Semicolon in C will remove ambiguity and confusion while looking at the code.
  4. They are not used in between the control flow statements but are used in separating the conditions in looping.
    for(initialization/declaration; condition; increment/decrements){ // body}

Role of Semicolon in C++:


Role of SemiColon in various Programming Languages - GeeksforGeeks (2)

  1. Semicolon is a command in C++.
  2. The Semicolon lets the compiler know that it’s reached the end of a command.
  3. Semicolon is often used to delimit one bit of C++ source code, indicating it’s intentionally separated from the respective code.
  4. Usage of Semicolon in C++ is after class and structure definitions, variable declarations, function declarations, after each statement generally.

Role of Semicolon in Java:


Role of SemiColon in various Programming Languages - GeeksforGeeks (3)

  1. Java uses Semicolon similar to C.
  2. Semicolon is a part of syntax in Java.
  3. It shows the compiler where an instruction ends and where the next instruction begins.
  4. Semicolon allows the java program to be written in one line or multiple lines, by letting the compiler know where to end the instructions.

Role of Semicolon in JavaScript:


Role of SemiColon in various Programming Languages - GeeksforGeeks (4)

  1. Semicolons in JavaScript are optional.
  2. In JavaScript, there is a process called Automatic Semicolon Insertion (ASI) which inserts a Semicolon whenever needed but not placed.
  3. Semicolons are also used to terminate the statements.
  4. Placing the new line next to the previous line will result in valid JavaScript which will not trigger ASI to correct it.
  5. So in conditional statements like if ..else and looping statements like while, for, do-while, doesn’t require Semicolon.

Role of Semicolon in Python:


Role of SemiColon in various Programming Languages - GeeksforGeeks (5)

  1. Python doesn’t use Semicolons but it is not restricted.
  2. In Python, Semicolon is not used to denote the end of the line.
  3. Python is called the simple coding language because there is no need to use Semicolon and if we even forget to place, it doesn’t throw an error.
  4. Sometimes Python makes use of Semicolon as line terminator where it is used as a separator to separate multiple lines.

Role of Semicolon in Perl:


Role of SemiColon in various Programming Languages - GeeksforGeeks (6)

  1. Perl language employs Semicolon after every line, except at the end of the block.
  2. Perl lets us omit the Semicolon because it can be used as a separator rather than a terminator.
  3. Every statement in Perl is terminated with Semicolon unless it is the last line of the program.

Role of Semicolon in SQL:


Role of SemiColon in various Programming Languages - GeeksforGeeks (7)

  1. Semicolon in SQL allows the user to execute the program in the same call by separating the statements in the database.
  2. SQL has a unique feature of adding Semicolon by default to terminate the statements.
  3. Semicolon is a statement terminator which is purely used to identify the end of a statement.
  4. Generally, by looking at the syntax, we can identify but using a Semicolon makes it more clear.

Role of Semicolon in Go language:


Role of SemiColon in various Programming Languages - GeeksforGeeks (8)

  1. Semicolon in Go language is used to separate the initializer, condition, and continuation elements.
  2. Semicolon is added as a terminator when the line’s last token is:
    • An integer, floating-point, imaginary or string literal
    • one of the keywords (eg. break, continue, return etc..,)
    • an identifier.
    • one of the operators and delimiters like ++, –, ), ], or }

Role of Semicolon in C#:


Role of SemiColon in various Programming Languages - GeeksforGeeks (9)

  1. C# makes use of Semicolon to get rid of ambiguity and confusion as its usage makes the code clear, structured and organised.
  2. Like other languages especially C and C++, C# also follows the same rules in the Semicolon application.
  3. The absence of Semicolon throws an error by the compiler which has to be rectified.
  4. It also lets the compiler know the end of the statement.

Role of Semicolon in Scala:


Role of SemiColon in various Programming Languages - GeeksforGeeks (10)

  1. Semicolon plays a vital role in all the programming language by marking the end of the statement.
  2. But Semicolon in Scala, not only marks the end of the statement but also the end of the expression.
  3. Scala’s syntax encourages clear and concise code, so it is necessary to use Semicolon properly whenever needed.
  4. Scala adapts different syntaxes like dot syntax, syntax using braces, syntax using parenthesis and syntax using empty line separator which replaces the use of Semicolon.

Role of Semicolon in PL/I:

  1. PL/I is a language which is a series of declarations and statements. So Semicolon is necessary to separate the statements to avoid ambiguity.
  2. Statements in PL/I should be placed in separate lines with Semicolon to improve the readability.
  3. In multi-line statements, Semicolon is used to separate the lines and in a single-line statement, Semicolon is used to terminate.

Role of Semicolon in Pascal:

  1. Semicolon in Pascal acts as statement separator i.e it separates two or more statements.
  2. Exactly one Semicolon should be used in separating two statements. But using more than one Semicolon (extra Semicolon) will raise an error.
  3. Unlike other languages, Pascal makes use of Semicolon in a different way. There is no need for a direct Semicolon before else in Pascal. Also, the last statement before the end of the code/program doesn’t need a Semicolon.
  4. Pascal needs Semicolon when statements are written in a sequence.
  5. Pascal doesn’t need Semicolon for a case or a block and also before the keyword.

My Personal Notesarrow_drop_up

Role of SemiColon in various Programming Languages - GeeksforGeeks (2024)

FAQs

What are the 5 uses of a semicolon? ›

Here are the rules for using semicolons correctly; we hope you're taking notes.
  • 1 Semicolons connect related independent clauses. ...
  • 2 Delete the conjunction when you use a semicolon between two independent clauses. ...
  • 3 Use semicolons in a serial list. ...
  • 4 Use semicolons with conjunctive adverbs. ...
  • 5 Use a semicolon to give a wink.
9 Nov 2022

Do all programming languages use semicolons? ›

Not all programming languages use semicolons as statement terminators. Python uses the newline character as a statement terminator, as does Visual Basic and Visual Basic.NET. Ruby is another popular language that doesn't use the semicolon this way.

What is the purpose of semicolon in Python? ›

A semi-colon in Python denotes separation, rather than termination. It allows you to write multiple statements on the same line. This syntax also makes it legal to put a semicolon at the end of a single statement: print('Why God?

What are the 3 ways semicolons are used? ›

3 Ways to Use a Semicolon
  • Use a semicolon to connect related independent clauses. An independent clause is a sentence that communicates a complete thought and makes sense on its own. ...
  • Use a semicolon with a conjunctive adverb or transitional phrase. ...
  • Use semicolons to separate items in a list.
7 Jun 2021

What is the significance of a semicolon? ›

This small punctuation mark—in grammatical terms—represents a place where a sentence could end, but continues on. This meaning has been transferred to suicide awareness and prevention as a symbol for battling through suicidal thoughts or behavior.

What programming language uses semicolons for comments? ›

End-of-Line Comments
LanguageComment Syntax
ALGOL 60; (semicolon)
Assembly Languages; (semicolon)
Ada, mySQL-- (two dashes)
C++/Java// (two slashes)
3 more rows
12 Feb 2004

What is the purpose of using semicolon in Java? ›

In Java, the semicolon is a separator that is used to terminate a statement. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity. As you know, a block is a set of logically connected statements that are surrounded by opening and closing braces.

When should a semicolon be used examples? ›

A semicolon can replace a period if the writer wishes to narrow the gap between two closely linked sentences (independent clauses). Examples: Call me tomorrow; you can give me an answer then. We have paid our dues; we expect all the privileges listed in the contract.

What are the types of semicolons? ›

In the English language, a semicolon is most commonly used to link (in a single sentence) two independent clauses that are closely related in thought.
...
Semicolon.
;
Semicolon
In UnicodeU+003B ; SEMICOLON ( ;)
؛ ፤ ꛶ Arabic semi colon Ethiopic semicolon Bamum semicolon

What does a semicolon tattoo mean for a girl? ›

While you don't have to get a semicolon tattoo because of its meaning, those who get the tattoo usually do so to honor someone—whether that's a friend, a relative, or themselves—or to raise awareness of mental illness, suicide, addiction, or self-harm.

Is semicolon important in JavaScript? ›

In some cases, omitting them may lead to bad consequences. A semicolon is required When two statements are on the same line. So if you're going to put two statements on the same line, you have to separate them with a semicolon. The semicolon is only obligatory when you have two or more statements on the same line.

Can a semicolon be used to start a list? ›

Semicolons Use in Lists: Long or Complex Content

In some cases we may also wish to create a list with semicolons if the text is long and increasingly complex for the reader to process. This is true even if the content does not have internal punctuation.

How do you use a semicolon in a complex list? ›

The general rule is to use a semicolon to separate list items if one of your items already contains a comma and to use one before the conjunction if the items are complex.

What is a list with Semicolons called? ›

Horizontal lists, lists that appear within written text, present a series of items without promoting the items as priority on the page (as a vertical list does). There are three punctuation marks that are particularly useful when presenting lists: the colon, the semicolon and the comma.

Top Articles
Latest Posts
Article information

Author: Arielle Torp

Last Updated:

Views: 5947

Rating: 4 / 5 (41 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Arielle Torp

Birthday: 1997-09-20

Address: 87313 Erdman Vista, North Dustinborough, WA 37563

Phone: +97216742823598

Job: Central Technology Officer

Hobby: Taekwondo, Macrame, Foreign language learning, Kite flying, Cooking, Skiing, Computer programming

Introduction: My name is Arielle Torp, I am a comfortable, kind, zealous, lovely, jolly, colorful, adventurous person who loves writing and wants to share my knowledge and understanding with you.