is there any way to modify the foreach variable from within the foreach body?
e.g.
Code: Select all
foreach Y = std::fromTo(1, 100) do
<command to change the value of Y>
implement this without recursion.
Michael
Code: Select all
foreach Y = std::fromTo(1, 100) do
<command to change the value of Y>
Code: Select all
Y = 1
While Y < 100,
<do steps>
< change value of Y (either increment by 1 or set to 100)>
End While.
Code: Select all
...
Y=1,
MyWhileLoop(Y, Omega), % Omega is the upper limit)
....
MyWhileLoop(Y, Omega):- %This is your 'while' loop
Y<Omega, !,
<do steps>
MyWhileLoop1(Y, Omega, NewOmega),
...
MyWhileLoop(Y, Omega).
MyWhileLoop1(Y, Omega, NewOmega):- % this is the looping 'control' (value of Y)
<do condition check for terminating>
!,
NewOmega = Y,
MyWhileLoop(Y, NewOmega ).
MyWhileLoop1(Y, Omega, NewOmega):-
NewY = Y +1,
NewOmege = Omega,
MyWhileLoop(NewY, NewOmega).