A statement ends either with a block (delimited by curly braces), or with a semicolon. "do this while this" is a single statement, and can't end with a block (because it ends with the "while"), so it needs a semicolon just like any other statement.
I am just curious as to why a 'do ... while' loop syntax needs a semicolon at the end. Whereas for and while loop do not need a semi-colon terminator at end.
A "double semicolon" does not have any special meaning in c. The second semicolon simply terminates an empty statement. So you can simply remove it.
Role of Semicolon in PL/I: PL/I is a language which is a series of declarations and statements. So Semicolon is necessary to separate the statements to avoid ambiguity.
The concept is known as JavaScript Semicolon Insertion or "Automatic Semicolon Insertion". This blog post: JavaScript Semicolon Insertion: Everything you need to know outlines the concept well in an understandable manner using examples under the headings:
It even digs into the official ECMAScript specification about the topic.
Javascript does something called "semicolon insertion" which means you can actually write code that omits the semicolon in certain places, and they'll basically be added for you when the code is parsed.
The rules around when this happens a little complex. For simplicity's sake, many developers simply pretend semicolon insertion doesn't exist.
You can write javascript without semicolon, you only need to insert them if you start a line with a parantesis (
or a bracket [
.
The sugarjs times()
function is a good example:
<script>
var somthing = 1 + 3
;(5).times(function(n){
console.log(n + " line") //prints "X line" 5 times
})
</script>
To say that writing code with semicolons makes it more readable is absurd. It makes your code more CLUTTERED. Look at the code on this page without the semicolons and tell me it's less readable. It's more readable, less cluttered, cleaner and more elegant. Semicolons are ugly and unnecessary. See this article: https://mislav.net/2010/05/semicolons/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With