• #### How to exit from "for t in C when f(t) loop" ?

From reinert@21:1/5 to All on Sun Oct 22 22:02:59 2023
Assume the loop:

for t of C loop
if f(t) then
do something....
elsif f(t) > f1 then
exit;
end if;
end loop;

I would like to simplify this construct (somehow) like this:

for t of C when f(t) loop
do something....
end loop;

However, this is not computationally effective, since t in this case runs through the whole C.
Any ideas for a compromise?

reinert

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From reinert@21:1/5 to All on Mon Oct 23 00:04:28 2023
mandag 23. oktober 2023 kl. 07:03:01 UTC+2 skrev reinert:
Assume the loop:

for t of C loop
if f(t) then
do something....
elsif f(t) > f1 then
exit;
end if;
end loop;

I would like to simplify this construct (somehow) like this:

for t of C when f(t) loop
do something....
end loop;

However, this is not computationally effective, since t in this case runs through the whole C.
Any ideas for a compromise?

reinert
Just a correction of the subject, it should be: How to exit from "for t *of* C when f(t) loop ? -reinert

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From minghia@gmail.com@21:1/5 to reinert on Tue Oct 24 19:32:56 2023
On Monday, October 23, 2023 at 6:04:30 PM UTC+11, reinert wrote:
mandag 23. oktober 2023 kl. 07:03:01 UTC+2 skrev reinert:
Assume the loop:

for t of C loop
if f(t) then
do something....
elsif f(t) > f1 then
exit;
end if;
end loop;

I would like to simplify this construct (somehow) like this:

for t of C when f(t) loop
do something....
end loop;

However, this is not computationally effective, since t in this case runs through the whole C.
Any ideas for a compromise?

reinert
Just a correction of the subject, it should be: How to exit from "for t *of* C when f(t) loop ? -reinert
Normally one does something
t := C'first;
loop
do something...
exit when Condition;
t := t + 1;
end loop;

The conditon is just a boolean expression. It can be as simple or as complicated as one desires.

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From reinert@21:1/5 to All on Fri Oct 27 07:53:13 2023
I would like an exit possibility somehow like this:

for t of C when f(t), but exit when f(t) loop
do something....
end loop;

Three lines less - keeping errors down :-)

reinert

onsdag 25. oktober 2023 kl. 04:32:58 UTC+2 skrev min...@gmail.com:
On Monday, October 23, 2023 at 6:04:30 PM UTC+11, reinert wrote:
mandag 23. oktober 2023 kl. 07:03:01 UTC+2 skrev reinert:
Assume the loop:

for t of C loop
if f(t) then
do something....
elsif f(t) > f1 then
exit;
end if;
end loop;

I would like to simplify this construct (somehow) like this:

for t of C when f(t) loop
do something....
end loop;

However, this is not computationally effective, since t in this case runs through the whole C.
Any ideas for a compromise?

reinert
Just a correction of the subject, it should be: How to exit from "for t *of* C when f(t) loop ? -reinert
Normally one does something
t := C'first;
loop
do something...
exit when Condition;
t := t + 1;
end loop;

The conditon is just a boolean expression. It can be as simple or as complicated as one desires.

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Jere@21:1/5 to reinert on Fri Oct 27 15:28:17 2023
On Friday, October 27, 2023 at 10:53:15 AM UTC-4, reinert wrote:
I would like an exit possibility somehow like this:

for t of C when f(t), but exit when f(t) loop
do something....
end loop;

Three lines less - keeping errors down :-)

reinert
onsdag 25. oktober 2023 kl. 04:32:58 UTC+2 skrev :
On Monday, October 23, 2023 at 6:04:30 PM UTC+11, reinert wrote:
mandag 23. oktober 2023 kl. 07:03:01 UTC+2 skrev reinert:
Assume the loop:

for t of C loop
if f(t) then
do something....
elsif f(t) > f1 then
exit;
end if;
end loop;

I would like to simplify this construct (somehow) like this:

for t of C when f(t) loop
do something....
end loop;

However, this is not computationally effective, since t in this case runs through the whole C.
Any ideas for a compromise?

reinert
Just a correction of the subject, it should be: How to exit from "for t *of* C when f(t) loop ? -reinert
Normally one does something
t := C'first;
loop
do something...
exit when Condition;
t := t + 1;
end loop;

The conditon is just a boolean expression. It can be as simple or as complicated as one desires.

Would the new Ada22 feature of iterator filters help at all? http://www.ada-auth.org/standards/22over/html/Ov22-4-6.html

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From AdaMagica@21:1/5 to reinert on Sat Oct 28 07:42:08 2023
reinert schrieb am Freitag, 27. Oktober 2023 um 16:53:15 UTC+2:
I would like an exit possibility somehow like this:

for t of C when f(t), but exit when f(t)
except when Y then skip next -- many more lines saved ;-)
loop
do something....
end loop;

Three lines less - keeping errors down :-)

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)
• From Stephen Leake@21:1/5 to AdaMagica on Sat Oct 28 10:16:08 2023
On Saturday, October 28, 2023 at 7:42:10 AM UTC-7, AdaMagica wrote:
reinert schrieb am Freitag, 27. Oktober 2023 um 16:53:15 UTC+2:
I would like an exit possibility somehow like this:

for t of C when f(t), but exit when f(t)
except when Y then skip next -- many more lines saved ;-)
loop
do something....
end loop;

'exit when condition;' is perfectly legal Ada.

It is more problematic that you are executing f(t) twice; that's either wrong if it has side effects, or wasteful if not.
And you are treating f(t) as returning a Boolean and a scalar!

for t of C loop
declare
A : foo renames f(t);
begin
exit when A; -- Boolean
exit when A >= f1; -- scalar
do something;
end;
end loop;

--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)