What Does a Semicolon Do

What does a semicolon do?

The semicolon does nothing in the code you show.

I suspect this is someone who programs in another language (C, Java, ...) that requires semicolons at the end of statements and it's just a habit (happens to me sometimes too).

If you want to put several Python statements on the same line, you can use a semi-colon to separate them, see this Python Doc:

A suite is a group of statements controlled by a clause. A suite can
be one or more semicolon-separated simple statements on the same line
as the header, following the header’s colon, or it can be one or more
indented statements on subsequent lines

What does the semicolon actually do?

The semiccolon is a separator of stack calls. The inside of if() wants a boolean, not a stack call.
Only inside the {} are statements expected.

The inside of for() expects three stack calls: One defining the loop variable, one defining the breaking clause and one defining what happens after each loop.

Example:
The construct for(;;); is a valid java construct. But you should never use it as the only thing it would do is loop over nothing forever: You don't define a variable, a breaking condition or something that gets executed after each call. During the loop you also just do nothing.

What's the difference in using a semicolon or explicit new line in R code

At the console, the script is evaluated as soon as the a line ends with a complete statement. Hence, this:

temp_a 
temp_b <- 1
temp_c <- 2

is equivelent to calling this:

source(textConnection('temp_a'))
source(textConnection('temp_b <- 1'))
source(textConnection('temp_c <- 2'))

in which each line is evaluated as soon as it is encountered, and failures
in previous lines don't prevent the subsequent lines from being evaluated.
On the other hand. this:

temp_a ; temp_b <- 1 ; temp_c <- 2

is equivalent to calling this:

source(textConnection('temp_a ; temp_b <- 1 ; temp_c <- 2'))

which is equivalent to this

source(textConnection('
temp_a
temp_b <- 1
temp_c <- 2'))

because when first line fails, the remainder of the code is not run.

Incidentally, if you want to mimic this behavior at the console, you can
take advantage of the fact that the lines are not evaluated until they make
a complete statement, by surrounding the three lines with braces to make a
single code block that is evaluated as a whole, like so:

{
temp_a
temp_b <- 1
temp_c <- 2
}

What does the semicolon do when it is run in a bash command?

The ; separates the two commands.

echo a; echo b

It lets the bash know that echo a and echo b are two separate commands and need to be run separately one after the other

Try without semicolons

$ echo a echo b
a echo b

Here the statement is taken as a single command echo and a echo b is passed as parameter to the echo

What does semicolon do in this Excel function?

As commented, ; semi-colon is an argument separator. FINV is a function requiring three(3) arguments with the following syntax:

FINV(probability,deg_freedom1,deg_freedom2)

So in your formula:

  • Probability is (1-E39/100)/2
  • Deg_freedom1 is B39-1
  • Deg_freedom2 is L39

Take note though that there are regional differences in Excel in terms of what default separator is being used (what you hinted in your question) which is greatly explained in this Excel Tip.

...there are also many regional differences when it comes to certain tasks in Excel, including separating arguments, writing numbers, and function names.

Why is semicolon allowed in this Python snippet?

Python does not require semicolons to terminate statements. Semicolons can be used to delimit statements if you wish to put multiple statements on the same line.

Now, why is this allowed? It's a simple design decision. I don't think Python needs this semicolon thing, but somebody thought it would be nice to have and added it to the language.

What is the semicolon in C++?

The semicolon is a punctuator, see 2.13 §1

The lexical representation of C++ programs includes a number of preprocessing tokens which are used in
the syntax of the preprocessor or are converted into tokens for operators and punctuators



Related Topics



Leave a reply



Submit