GoTo Statement

FlamingClaw 0 Tallied Votes 1K Views Share

Many people says 'Don't use the GoTo statement,because your code will be unreadable....'.I say,can be use

(*For those who now get on the train,'cause there are beginers always..*)
Program GoToExample;
Uses Crt;
Label here,there;
Var  ch:Char; {from ASCII}
Begin
     here:WriteLn('1,You''re here');
     WriteLn('Where are you going?');
     WriteLn('Press ''1'' for here,press ''2'' for there.: ');
     Ch:=ReadKey;{catch the answer}
     Case (Ch) Of    {analize it}
          #49:GoTo here;        {jump up}
          #50:GoTo there        {go down}
     Else Begin
               WriteLn('Wrong answer!');{if no matches then jump up}
               GoTo here;
          End;
     End;

     there:WriteLn('2,You''re there');
     ReadKey;
End.
(*
Release Note:
#49=1 button
#50=2 button from the keyboard
When asked 'Where are you going?',you'll press 1 or 2 button.
The choice is yours:If press 1 button then the program go up to the
label named 'here'.But if you press 2 button then the program jump down
to the 'there' label and the program will end*)
ddanbe 2,724 Professional Procrastinator Featured Poster

Here,there and everywhere...all over the place, start a course on cooking spagetti. Stop programming if you want to continue on this way, else try to use a while loop.

FlamingClaw 98 Posting Pro

Ok,I understand you 'ddanbe'....but there are times when you want to know many things about your favorit language (pascal)
and there are things that you can write but not really understand.
When I found this page,I thought :I find the right place,many language,nice works....but the pascal snippet was very gappy....
From that time,I'll try to write mini programs that demonstrate an solution,that helps beginners to understand.....and what about you?Why don't write you too?...The answer is that:'cause...
I know that the 'GoTo' command is not a good choice to create good program,but thereform the 'GoTo' is exists.....and the part of the Pascal language since 1973.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.