Quick Quiz #2 - Semicolons - Solutions

Programming language questions

Quick Quiz #2 - Semicolons - Solutions

Postby cfbsoftware » Sat Nov 29, 2014 11:06 am

Please post your solutions and explanations to Quick Quiz #2 as a reply to this message.
cfbsoftware
 
Posts: 37
Joined: Wed Sep 18, 2013 10:06 pm

Re: Quick Quiz #2 - Semicolons - Solutions

Postby Robert » Sat Nov 29, 2014 11:38 am

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

Robert
User avatar
Robert
 
Posts: 140
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: Quick Quiz #2 - Semicolons - Solutions

Postby manumart1 » Sun Nov 30, 2014 11:44 am

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
manumart1
 
Posts: 67
Joined: Tue Sep 17, 2013 6:25 am

Re: Quick Quiz #2 - Semicolons - Solutions

Postby Robert » Wed Dec 03, 2014 11:19 am

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
User avatar
Robert
 
Posts: 140
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland


Return to Component Pascal

Who is online

Users browsing this forum: No registered users and 1 guest

cron