Wednesday, December 25, 2024
Google search engine
HomeLanguagesRole of SemiColon in various Programming Languages

Role of SemiColon in various Programming Languages

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:

  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++:

  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:

  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:

  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:

pythonTutorials

  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:

perl-Tutorial

  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:

  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:

Golang-Tutorial-Learn-Go-Programming-Language

  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#:

C#-Tutorial-A-Complete-Tutorial-For-Beginners

  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:

  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.

RELATED ARTICLES

Most Popular

Recent Comments