#What is only a semi colon not a error in Java or an IDE like netbeans?
1 messages · Page 1 of 1 (latest)
<@&987246527741304832> please have a look, thanks.
Here is an AI assisted attempt to answer your question 🤖. Maybe it helps! In any case, a human is on the way 👍. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
In Java and IDEs like NetBeans, a single semicolon is not considered an error when it is used to terminate a statement. In fact, the semicolon is used to separate statements in Java code and is mandatory at the end of each statement for proper syntax. Without a semicolon, the compiler will throw an error indicating that the statement is incomplete.
However, if a semicolon is used in a context where it should not be present, such as after a conditional statement or inside a method declaration, it will be flagged as an error by the compiler or IDE. This is because the semicolon serves as a terminator for statements and should only be used in appropriate places within the code.
Overall, a single semicolon on its own is not considered an error in Java or IDEs like NetBeans when used correctly to terminate statements. It is an essential part of Java syntax and plays a crucial role in separating different parts of the code for proper execution.
wdym
I didnt realize there was only a semicolon in a line in my java as it was not considered an error by netbeans, I found it strange as only a semicolon by itsefl is not a statement right?
it is
hmm; but why?
no idea, but it exists
there are some use tho
like while(true);
or if you prefer
while(true)
;
Because it’s just an empty statement
That’s why if(;;) is an infinite loop
Initialize nothing
Keep doing contents till nothing happens
Do nothing
whats the use case though? @still smelt @autumn venture
None
It doesn’t do anything
It’s the equivalent of an empty line
And you can’t throw an error from a line that doesn’t do anything
Sry I meant for(;;)
its called a NOP
(no operation)
syntax-wise, it can have benefits to support that
as part of the buildings blocks of the language
so that u have a way to write a statement when the language expects one from u even if u dont want to write any
as shown above with the for(;;)
or a dummy lambda x -> ; etc
in practice however, chances are u will never use it
I've used while (somethingThatConsumesPartOf(x)); before. Because an empty body is rare, it was accompanied by a comment of course.
Also think about this
doThing();;
very easy to do by accident, hard to find, doesn't actually affect anything to allow
so interpreting ; as "empty statement" has some value
got it thanks