PDA

View Full Version : [TUT] else and end else



NCDS
08-02-2009, 01:27 AM
Figured I would clear this up for some of the beginner scripters.


Just think of else like you would in real life. Do something, or else do something else. Well, that's the same way it works in Scar.

Now, Ill show you...

else


procedure TeachEm;
begin
if (ThisReturnsTrue) then
DoThis
else
DoThis;
end;

Notice that there is not a semicolon after the first "DoThis" but there is after the second one.
Well, this is because if you put a semicolon before an else Scar will return an error.
Seems easy enough right?

end else

end else is just two basic things put together. Obviously, end and else.
Ex:

procedure TeachEm;
begin
if (ThisReturnsTrue) then
begin
DoThis
andthis
end else
DoThis2;
end;

As you all know (if not then now you do) if..then statements will only execute the line after it unless that line is a "begin". In which case it would execute what is between the begin..end nest.

Thats where end else comes in.
So,

if (ThisReturnsTrue) then

Scar will execute:

DoThis
andthis


But,

if (ThisReturnsTrue) then

Doesn't return true, then Scar will execute this:

DoThis2;


You see? quite simple.

If anyone needs more explanation feel free to ask.

ShowerThoughts
08-02-2009, 01:31 AM
You may go a little bit in depth, afaik ; is to end a command.
If you do:

if something then lol;else lol;

You should exit ALWAYS after the first lol; so the statement wouldn't work.

Method
08-02-2009, 01:35 AM
Why don't you have semicolons in the second TeachEm procedure? They shouldn't cause any errors there.

NCDS
08-02-2009, 01:42 AM
You may go a little bit in depth, afaik ; is to end a command.
If you do:

if something then lol;else lol;

You should exit ALWAYS after the first lol; so the statement wouldn't work.
Don't understand that post at all...


Why don't you have semicolons in the second TeachEm procedure? They shouldn't cause any errors there.
Copy and paste issues I suppose. I didn't even realize it >.<
Thanks for pointing it out I'll change it.

EDIT:
Wont let me edit it? says post is too short please lengthen to 3 chars. hmm..

ShowerThoughts
08-02-2009, 02:53 AM
How to say...
the interpreter reads the stuff you written, alright?
If it reads this ; then it stops and tries to perform the command.
if you do if something then lol1; else lol2;
You end it always after lol1 so it will not read any further.

NCDS
08-02-2009, 08:25 AM
How to say...
the interpreter reads the stuff you written, alright?
If it reads this ; then it stops and tries to perform the command.
if you do if something then lol1; else lol2;
You end it always after lol1 so it will not read any further.

That why I put:


Notice that there is not a semicolon after the first "DoThis" but there is after the second one.
Well, this is because if you put a semicolon before an else Scar will return an error.

;)

ian.
08-02-2009, 09:33 AM
How to say...
the interpreter reads the stuff you written, alright?
If it reads this ; then it stops and tries to perform the command.
if you do if something then lol1; else lol2;
You end it always after lol1 so it will not read any further.

SCAR won't even compile if you do if(Something)then SomethingElse; else TheOtherThing;.. So I don't see why you're talking about that in the first place.. >_>

ShowerThoughts
08-02-2009, 05:36 PM
How to say...
the interpreter reads the stuff you written, alright?
If it reads this ; then it stops and tries to perform the command.
if you do if something then lol1; else lol2;
You end it always after lol1 so it will not read any further.


That why I put:


Notice that there is not a semicolon after the first "DoThis" but there is after the second one.
Well, this is because if you put a semicolon before an else Scar will return an error.

;)


SCAR won't even compile if you do if(Something)then SomethingElse; else TheOtherThing;.. So I don't see why you're talking about that in the first place.. >_>

Sigh, you both say it gives an error, I said that you should add why it raises an error and not only say if you do this it gives an error.
If you know why things happen you understand them faster/easier it works great for me.(that method)

ian.
08-02-2009, 06:08 PM
Sigh, you both say it gives an error, I said that you should add why it raises an error and not only say if you do this it gives an error.
If you know why things happen you understand them faster/easier it works great for me.(that method)

Oohhh. I didn't know that's what you were trying to say haha. :)

ShowerThoughts
08-02-2009, 06:34 PM
Oohhh. I didn't know that's what you were trying to say haha. :)

It's fine I could have been a little bit more clearly.

Richard
08-03-2009, 01:04 AM
In if statements, you never have a semicolon on the last line, so in the case of having a begin end nest, the end doesn't have a semicolon. End else is in fact just 2 lines of code put into one, its really just

end
else

NCDS
08-03-2009, 01:15 AM
I understand that, but I explained them separately just because they are used in two different instances and there seems to be more questions about something this simple than there should be, honestly.

Thanks though :)