do i need the ; after end or not. it works both ways??

Go down

do i need the ; after end or not. it works both ways??

· #1

sometimes i write end; and sometimes end and it compiles both ways

is the semicolon decoration

Re: do i need the ; after end or not. it works both ways??

· #2

Not decoration, but you've noticed something real.

A semicolon separates statements. It doesn't end them. So before an end it's optional, because there's nothing after it to separate from:

pascal
begin
  WriteLn('one');
  WriteLn('two')    // no semicolon needed here, "end" comes next
end;

Both compile. Most people write the semicolon anyway, so that adding a line later doesn't break anything.

The places where it is not optional:

Where Semicolon?
Between two statements required
Before end optional
Before else forbidden
After the final end of a program it's a period: end.

Read the error message. Then read it again.

Re: do i need the ; after end or not. it works both ways??

· #3

whoa

so the last one is a dot

i have been putting a semicolon there and then deleting things until it compiled

Re: do i need the ; after end or not. it works both ways??

· #4

That is, in fairness, how most of us learned.

Pete · thirty years of begin and end "It compiled on my machine."

Re: do i need the ; after end or not. it works both ways??

· #5

THE PROGRAM ENDS WITH A PERIOD BECAUSE IT IS A SENTENCE

that is actually kind of beautiful. sorry

SORRY ABOUT THE CAPS

Re: do i need the ; after end or not. it works both ways??

· #6

For once I have nothing to add. Mark the calendar.

Forum rules 1 to 10 apply. Yes, to you.

Go up

Sign in to reply