semicolon or not semicolon?

20 views
Skip to first unread message

wheelie tips

unread,
Dec 7, 2021, 11:42:25 PM12/7/21
to DroidScript
Hello,
Does DS need the semicolon at the end of each line or not? what is the best practice?
Best,
WT

Steve Garman

unread,
Dec 8, 2021, 2:26:12 AM12/8/21
to DroidScript
Semicolons that are just line terminators have never been strictly necessary in DroidScript if the lines are separated by \n or \r or both

They were regarded as good practice at one time but DroidScript has removed them recently from it's samples and no longer recommends them as best practice

Steve Garman

unread,
Dec 8, 2021, 2:31:23 AM12/8/21
to DroidScript
I should add that there is no reason to remove them from your existing code unless you want to

It is merely a style choice

They have no effect either way on the efficiency of the code

wheelie tips

unread,
Dec 8, 2021, 2:36:21 AM12/8/21
to DroidScript
Very well, thx much for the clarification!
WT

Alan Hendry

unread,
Dec 8, 2021, 7:32:28 AM12/8/21
to DroidScript
HI,

If you put multiple statements on a line it is necessary to separate them
const i = 5 ; var j = i + 1 ; alert (j) // not needed at end of line
{alert(i);alert(j);alert(k)} // not needed before or after curly bracket

Confusingly it seems to be required after a 
do{...} while (...) ; 
but should be omitted after
while (...) {...}

If you have a very long "for" statement and break into multiple lines, I believe they are needed
for (i=0 ; 
  i < len ; 
  i++)  // no semicolon before round bracket
  { ... }

There are definitely cases where you don't want them
if (i == 1) ; { alert("hi") }
(if the test is true it does nothing, and always does the alert)

Regards, ah

wheelie tips

unread,
Dec 8, 2021, 7:34:51 AM12/8/21
to DroidScript
Thank you Alan!! your input is highly appreciated!! 
Reply all
Reply to author
Forward
0 new messages