I know it’s frowned upon to use or abuse the ‘goto’ statement, but for special use cases … This Oxygene test case essentially comes from the documentation, but fails to compile:
/* Gary Chike testing 'goto' statement in Oxygene 08/29/2022 */
namespace Goto_Oxy;
var x : Integer := 5;
begin
writeLn('Hello');
if x > 5 then
goto Here;
writeLn('x is five or less');
Here: writeLn('World');
end.
@ck Thank you Carlo for taking a look. I see the issue now - the colon : operator in Oxygene is essentially the equivalent of C#'s null-conditional operator ?. also known by a variety of names in other languages (eg. safe navigation operator, etc…) unless you really meant the ternary operator ?: I know, C# is a little different in its nomenclature:
Fortunately, it appears that post-fixing a semi-colon, essentially truncating the label to its own statement, appears to be a very easy ‘workaround’ or could easily be the ‘fix’. There are variety of variations of the gotolabel in other languages, that it would not seem out of place by simply adding a semi-colon. Some Pascal dialects require the declaration of a label and I’m not sure if label is keyword in Oxygene. Could adding the declaration of a label help? Maybe it’s not necessary. The code below is written in a spiritual cousin of Oxygene (PascalABC.Net) demonstrating the label declaration. But interestingly enough, it works with a semi-colon post-fixed to the label.
var x : Integer := 5;
label Here;
begin
writeLn('Hello');
if x > 5 then
goto Here;
writeLn('x is five or less');
Here:; // works with or without semi-colon
writeLn('World');
end.
Yes, I believe that works nicely as well Marc. The code snippet below is the beginning of an old-school interactive console game loop and your suggestion works as expected. Should it be decided that this will not be ‘fixed’ as a bug, perhaps the workaround (or solution) should be mentioned in the documentation? Lest someone else gets tripped up. Just a thought …
namespace huwGameLoop_Goto_Oxy;
uses System.Threading;
begin
var userInput : nullable String;
writeLn("Press <q> to exit..");
repeat
Start:begin // Per Marc Hoffman's suggestion
write("> ");
end;
userInput := readLn;
if String.IsNullOrWhiteSpace(userInput) then goto Start;
writeLn($"You wrote '{userInput}'");
until userInput.ToLower() = "q";
writeLn("Goodbye!");
Thread.Sleep(2000);
end.
Interestingly enough, I was reading over the documentation on the use of label on the freepascal wiki site and it appears the semi-colon ; is actually used with the label in special cases:
Pascal imposes further restrictions on labels: Labels have to be associated with statements: Putting a label right before an end is not allowed. To bypass that, you can insert an empty instruction ; right after the label definition.