Many people says 'Don't use the GoTo statement,because your code will be unreadable....'.I say,can be use
GoTo Statement
(*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*)
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.