Thank you everyone and especially Aeric for digging in and finding a complete solution. I can see more clearly now that B4X is a RAD tool geared for GUI-based solutions. There seems to be quite a bit of "hand-rolling" code in B4X to write a simple interactive console-based application... phew! ? And honestly, at a beginner to intermediate level, I don't fully understand some of the code, but I can copy and paste
By the way, Aeric, I combined your above solutions into one solution below which incorporates the sleep routine and input prompt. It works nicely and as expected.
Sub Process_Globals
Private reader As TextReader
End Sub
Sub AppStart (Args() As String)
Dim user_input As String
PrintLn("Press <q> to exit..")
Do Until user_input.ToLowerCase = "q"
user_input = Input("> ")
PrintLn("You entered '" & user_input & "'")
Loop
Print("Goodbye!!")
Quit
StartMessageLoop
End Sub
Sub Quit
Sleep(2000) '2 second delay
StopMessageLoop
End Sub
Sub Input (Prompt As String) As String
Dim sys As JavaObject
sys.InitializeStatic("java.lang.System")
Print(Prompt)
Private reader As TextReader
reader.Initialize(sys.GetField("in"))
Return reader.ReadLine
End Sub
Sub Print (Message As String)
Private jo As JavaObject = Me
jo.RunMethod("print", Array(Message))
End Sub
Public Sub PrintLn (Prompt As String)
Private nativeMe As JavaObject = Me
nativeMe.RunMethod("javaPrintln", Array(Prompt))
End Sub
#If JAVA
public static void print (String message) {
System.out.print(message);
}
public static void javaPrintln (String prompt)
{
System.out.println(prompt);
}
#End If
The B4X code above essentially works like this very terse code in FreeBasic, QB64 or cousins:
Dim user_input as string
Print "Press <q> to exit.."
do
Input "> ", user_input
Print "You entered '" + user_input + "'"
Loop Until LCase$(user_input) = "q"
Print "Goodbye"
Sleep(2000)
End
and like this Java code:
package huw_game_loop;
import java.util.Scanner;
public class huwGameLoop {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args) throws InterruptedException
{
var userInput = "";
do
{
System.out.print("> ");
userInput = input.nextLine();
System.out.println("You wrote '" +userInput+ "'");
} while(!userInput.equalsIgnoreCase("q"));
System.out.println("Goodbye!");
Thread.sleep(2000);
}
}
or even this
Object Pascal derivative that runs on .NET.
//Of course, this is not C :->
program IOConsoleLoop1;
var userInput : String;
begin
Writeln('Press <q> to exit..');
repeat
begin
write('> ');
userInput := ReadString;
writeln($'You wrote ''{userInput}''');
end;
until userInput.ToLower = 'q';
Writeln('Goodbye!');
Sleep(2000);
end.
Thanks again everyone!