Quick Quiz #2 - Semicolons - Solutions

Programming language questions
Post Reply
cfbsoftware
Posts: 55
Joined: Wed Sep 18, 2013 10:06 pm
Contact:

Quick Quiz #2 - Semicolons - Solutions

Post by cfbsoftware »

Please post your solutions and explanations to Quick Quiz #2 as a reply to this message.
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Quick Quiz #2 - Semicolons - Solutions

Post by Robert »

All - before it will compile to my satisfaction!
None - if you are not so picky.

Robert
manumart1
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am

Re: Quick Quiz #2 - Semicolons - Solutions

Post by manumart1 »

How many semicolons need to be removed from the following code snippet before it will compile?
It does not say "can (optionally)", it says "need to".
My answer is: none of the semicolons need to be removed.

I know that the semicolon is a separator of statements, not a terminator, and that the empty statement was introduced in the language in order to admit a semicolon before "ELSE", "END", etc.
So, although I have not tested, I think that it would be even possible to write:

Code: Select all

IF j = 0 THEN;;;
;;ELSE;;
;END;;;
Regards,
Manuel
User avatar
Robert
Posts: 177
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Quick Quiz #2 - Semicolons - Solutions

Post by Robert »

I was gently criticising the question because what will compile is not the only merit criterion.

One might also want to give consideration to other factors, for example the Programming Conventions document that says
Semicolons are used to separate statements, not to terminate statements. This means that there should be no superfluous semicolons.
Robert
Post Reply