:
This message was edited by Opius at 2003-2-24 16:15:50
: : I know you can use Labels in Basic, and I think C++, but can you use them in pascal?
: :
: : In basic, you would use:
: :
: : LabelX:
: : //code
: : if a = 5 then
: : GOTO LabelX;
: : end
: :
: :
: : If there are labels (Surely there are, right?) how would you use them?
: :
:
:
: Labels/Goto statements are an integral part of spaghetti code. Fortunately (or unfortunately), there are no label/gotos in any strutctured programming language such as C++ or Pascal, at least as far as I know. An easy way to do this sort of thing is to use procedures and functions. Example
Personally I havent ever used GOTO, but like everything there is a time and place for it. And Pascal does support it. Here is an example (written from memory, it may not be syntactically correct)
procedure Test;
label
Bottom;
var
Ch: Char;
begin
while (1=1) do
begin
Ch := ReadKey;
if (Ch = #27) then
Goto Bottom;
end;
:Bottom
WriteLn('Used GOTO to exit the loop');
end;