There is still a use for GOTO, surely?
I read somewhere that the fpc compiler loves GOTO statements, as they optimise to machine code easily.
It's surprising that the current version of Laz/FPC still supports the LABEL and GOTO commands because they have been unfashionable for decades. I did remember the syntax though..
Quick 'n dirty string input routine using LABEL and GOTO that won't let go until szPW is assigned a non-blank string:
var
iRetries:Integer;
sz,szPw:String;
LABEL STARTAGAIN,RETRYPW;
begin
iRetries:=3;
RETRYPW:
sz:='';
If iRetries=0 then GOTO STARTAGAIN;
If InputQuery(
Format('Input password. Tries left %d',[iRetries]),
'Please type in a non-blank passowrd',TRUE, sz) then
szPW:=sz
else // user closed query
begin
Dec(iRetries);
GOTO RETRYPW;
end;
STARTAGAIN: // user cancelled 3 times
iRetries:=3;
If (sz = '') then GOTO RETRYPW; // user entered nothing
ShowMessage(szPW);