Ada input from a terminal

Who can tell me if there is a routine that can wait till an answer is given, Get or Get_line do not stop to gen the input from a terminal.
I have a simple example of what I want:

with Ada.Text_IO; use Ada.Text_IO;

  loop 
     Put("vak y, between 0 and 10 : ");
     str := Get_Line;
     vak_y := integer'Value(str);
     exit when (vak_y > 0 and vak_y < 10);
     Put_Line("End Vak_y");
 end loop;

Here I want to get a number between 0 and 5, each time you get a wrong answer the question should be put again

Seems to me that Get_Line does indeed do the trick, but you haven’t provided a full example. In particular, what’s the type of str?

Here’s the program I’m using that seems to work just fine:

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Get_Line is
Vak_y: Integer;
begin
  loop 
     Put("vak y, between 0 and 10 : ");
    declare
     str : String := Get_Line;
    begin
     vak_y := integer'Value(str);
     exit when (vak_y > 0 and vak_y < 10);
     Put_Line("End Vak_y");
    end;
 end loop;
end Test_Get_Line;

I just tried on my end and both Get and Get_Line wait on input for me. Get_Immediate does not wait as expected as well.

Maybe a weird terminal setting?

I used str : strng( 1.. 1); as a declaration in just above the loop

Then whenever there is more than one character on the line, you should ge Constraint_Error.
What do you see?

Then you should be using Get_Immediate

     Get_Immediate (Item => Str (1) );
     Vak_Y := Integer'Value (Str);

Of course, if the user enters a non-digit Character, this will raise Constraint_Error.

(Contrary to what @jere said, Get_Immediate without the Available parameter does wait for a Character to become available.)

You might also want to try writing idiomatic Ada:

exit when Vak_Y in 1 .. 9;

I do have the following code now :

procedure Get_Block is
str : string(1 .. 100);
begin
Put_Line(“Start square”);
loop
Put("vak x = ");
Get_Immediate(str(1));
Vak_x := Integer’Value (Str);
Put_Line(“End Vak_x”);
exit when (vak_x > 0 and vak_x < 10);
end loop;
loop
Put("vak y = ");
Get_Immediate(str(1));
Vak_y := Integer’Value (Str);
Put_Line(“End Vak_y”);
exit when (vak_y > 0 and vak_y < 10);
end loop;
Put_Line(“Stop Get_Block”);
end Get_Block;

I just missed printing the results:

Start Fill_Block
Stop Fill_Block
Start square
vak x = 5 5 my input

[2026-03-07 17:39:04] process exited with status 1, elapsed time: 04:13.99s

The results are not on the correct position the vak y is not even reached

This cannot be the output of what you’ve shown!

This is the answer I get. The only way I see that can be done if Get_Immidiate does not wait long enouh on the input to make it usable for my intention. I think some one must have solved this problem earlier.

To be specific: In your code, there is no output with “Fill_Block”, no “my input”.
So you do not show your complete code! How do you expect to get a correct answer?

There are more problems.
Vak_X and Vak_Y are not declared.
Integer’Value (Str) of an uninitialized string is not supposed to work. You only assign the very first character. See the RM how the image attribute works. Do your work before asking here!

As the program worked with I was thinking that for the values not declared or initiated in this routines that was done outside. For values and routines that are needed in more two packages I use a separate package “General”, if possible only the spec. So vak_x and vak_y are delared in “General.ads”. I think I know how the image attribute works because I printed the correct value 5 I gave in (as a string ) and that conversion worked but further on it was printed again without string I wanted. I had looked before asking hereon several positions on internet. I found answers saying
use Get, Get_Line or Get_Immidiate and found as many saying don’t use Get, Get_Line or Get_Immidiate. So I got on this forum in the hope that someone had tackled the problem, already and created a solution to be found on GitHub or somewhere other place as free software.

RM A.10.8(6-10/3) Get from file, (15) Get from String for integer types. You can use (21) Ada.Integer_Text_IO, so you do not need to instantiate Ada.Text_IO.Integer_IO.
RM A.10.1 Ada.Text_IO:
(41/5) Get for Character
(44/5,45/5) Get_Immediate for Character
(47/5) Get for String
(49/5) Get_Line
There is enough information for you to choose what you need.

By seriously testing with Get, Get_Line and Get_Immediate My conclusion is reading from a keyboard does not see a Line Terminator. I tested that by simply showing the complete string I entered up to that moment and when I wanted the reading to printing “End input”. At the moment I ran the program I got with Get

Start Program
123 abc --enterd string
1
12
123
123
123 a
123 ab
123 abc
– waiting for further input

Entering END_OF_LINE to find the end of the string does not had any effect. So how can I get a correct Lineterminator at the end of the string from the keyboard

From the Ada RM for Get :
After skipping any line terminators and any page terminators, reads the next character from the specified input file and returns the value of this character in the out parameter Item.

This means any EOL will be skipped.
Try calling End_Of_Line function before Get consumes and discards EOL

Please read A.10.6 as an overview of Get, especially the examples at the end.
Then read the explanation for each Get (Character, Integer, Real) and for Get_Line, A.10.7(18).
Get A.10.8 for integer, A.10.9 for real.

Line: String (1 .. 10); – can hold 10 characters

loop
  Get_Line (Line, Last);
  Put_Line (Line ('"' & 1 .. Last) & '"');
end loop;

1234567890         1234567890
Input              Line (1 .. Last);    Last
____________________________________________________________
ab<eol>           "ab"              <-- 2    <eol> consumed
  ABC   <eol>     "  ABC   "        <-- 8    <eol> consumed
1234567890<eol>   "1234567890"      <-- 10   <eol> not consumed
                  ""                <-- 0    <eol> of previous line consumed, empty line
  loop
     Put_Line("Start Read");
    Get_Line (Line, Last);
        n := n + 1;
     if n = last then
        exit when n = last;
     end if;
 end loop;

Result

Sorry, Something went wrong.
This is the loop you send me with som extra Put_Line lines

  n := 1;
  loop
     Put_Line("Start Read");
     Get_Line (Line, Last);
     n := n + 1;
     Put_Line ("Line 1 .. last");
     if n = last then
        exit when n = last;
     end if;
  end loop;

The result is:
Start lezen string : some text before the loop
Start Read : First text within the loop
123SW?><mn end input : Input given

The program comes in a loop as can be seen probably somewhere in Get_Line
With a system app I can see that the program is still running

I tried the following function:

function Read_unb return Unbounded_String is
Out_Line : Unbounded_String;
In_Char : character;
avail : boolean;
n : integer ;
begin
Put_Line (“Start Read_unb”);
n :=0;
Out_Line := To_Unbounded_String(“”);
while not end_of_line
loop
Get_Immediate(In_Char, avail);
avail := true;
if avail
then
n := n + 1;
Append(Out_Line, In_Char);
Put_Line (In_Char & " " & To_String(Out_Line));
end if;
if n = nr_char or In_Char = CR or In_Char = LF
then
exit;
end if;
end loop;
Put_Line(“End Read_unb”);
return Out_Line;
end Read_unb;

I tried the input:
abc the answer was:

Start Read_unb
a a
b ab
c abc

The program still is running and must be stopped by “Task Management” This means that he Line Terminator as given by keyboard is still notknown