Questions tagged [semicolon-inference]

Use this tag for questions about semicolon-inference in programming languages, which determines if semicolon are necessary or not.

Semicolon-inference is the ability of a programming language to work without semicolon. That means the compiler can decide by itself if a statement is complete or not.

A line ending is treated as a semicolon unless one of the following conditions are true:

  • The line ends in a word that would not be legal as the end of a statement
  • The next line begins with a word that cannot start a statement
  • The line ends while inside parentheses(...) or brackets[...]
15 questions
6
votes
1 answer

Why no semicolon after Ok(()) at the end of a function in rust?

Code snippet taken from the documentation on current_dir: use std::env; fn main() -> std::io::Result<()> { let path = env::current_dir()?; println!("The current directory is {}", path.display()); Ok(()) } I noticed that only by adding…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
3
votes
2 answers

When is semicolon mandatory in scala?

I am learning how to program in Scala and was being told that semicolon is optional in Scala. So with that in mind, I tried with the following nested block of code which does not have semi colon. However, it throws an error in the Scala REPL scala>…
Mox
  • 2,355
  • 2
  • 26
  • 42
2
votes
0 answers

param un-optional semicolon on struct

I am currently updating a lot CF 11 code to CF 2018. One of the things I like is that semicolons are options most of the time. Having said that, I am stuggling with the thinking behind this: Error rc = {} param rc.data2 =…
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
1
vote
4 answers

How kotlin compiler understands the end of statement if semicolon is optional in kotlin?

In java we use semicolon, on the basis on semicolon compiler understands an end of a statement. Whereas Kotlin also uses JVM How the compiler understands this is the end of statement without semicolon in Kotlin?
1
vote
1 answer

if statement fails when used after semi-colon separator

I don't understand why I'm having an error with Python when I use a single-line if statement after a semicolon (used as a statement separator). This is ok: if True: print("it works") #### it works But this gives a syntax error: a=1; if True:…
agenis
  • 8,069
  • 5
  • 53
  • 102
0
votes
0 answers

javascript backquoted strings and semicolon

This little situation in JavaScript was driving me crazy. The contents of the SQL string are unimportant. However, the line I commented as [1] simply was not executing. Other lines after it were executing. I tried to power past the problem by…
Joymaker
  • 813
  • 1
  • 9
  • 23
0
votes
0 answers

Non optional semicolons in JavaScript?

Look at the following pieces of code let a = 1; let b = 2; [a,b] = [b,a] console.log(a); // logs 2 console.log(b); // logs 1 now the same code with above, but without semicolons in the variable declarations - initializations: let a = 1 let b =…
Dimitris
  • 3
  • 1
  • 4
0
votes
0 answers

Why semicolons influence the behaviour of my javascript code?

I'm writing a quick sort function in Javascript to sort an array of objects like this (sort by the Num property): let Pairs = [ { ID: 'C', Num: 21 }, { ID: 'B', Num: 45 }, { ID: 'F', Num: 0 }, { ID: 'E', Num: 1 }, { ID: 'D', Num: 9…
0
votes
1 answer

Missing semicolon error msg at the start of function (react)

Overview: I just started learning react and I want to create a where, after the "Submit" button is pressed I get an alert with the monthly income * 2 (Calc() function). However when I writhe the Calc() function I geht a parsing error and the msg…
Julius
  • 1
  • 3
0
votes
1 answer

Semicolons appeared in CSV file when upload into R

I was instructed by the book Analyzing Financial Data and Implementing Financial Models Using R (Clifford S. Ang 2015, chapter 8) to download the USA real GDP data from IMF website https://www.imf.org/en/home. The downloaded file is a .xls, and I…
0
votes
0 answers

What if I don't end a javascript function with a semicolon?

I'm working on javascript about a week, and I noticed that Visual Studio don't flag you a function if you don't end it with a semicolon: function secondalert(){ alert ("Hi") } secondalert(); So as you can see i don't end the function with any…
user14339440
0
votes
1 answer

How can I run ES6 semicolumnless code in a windows 10 cmd window without babel?

How can I run a short ES6 (Javascript) program without semicolons? I have the following code in a jstry.js file let v = 1 console.log(v) I open a CMD window in windows 10, run it and get an error that a semicolon is expected. What can I change…
pashute
  • 3,965
  • 3
  • 38
  • 65
-2
votes
2 answers

Getting error SyntaxError: Missing semicolon

Checked the code and cannot find where I need to put a semicolon. Here is error. Here is the code.
-2
votes
3 answers

RegEx that matches characters after semicolon in the same line

I need some help with the Regular Expressions. I need a RegEx that matches with characters if they are after a semicolon AND in the same line of a previous word. Let me explain that: I need something like this. I have to make a function that does…
Carlos Pérez
  • 167
  • 1
  • 10
-3
votes
2 answers

while loop has terminating sign still works well

I was implementing Newton Raphson method in C. The code work well. There is no error in the code. #include #include #define f(x)(x * sin(x)+cos(x)) #define df(x)(x*cos(x)) int main() { float x,h,e; e=0.0001; printf("Enter…
Encipher
  • 1,370
  • 1
  • 14
  • 31