Re: for loop in prolog



On Tue, 10 Jan 2006 21:29:20 +0200, nobody wrote:

> hi to all,
>
> How could i implement a for loop in prolog. Let's say for
> example that i have an integer variable X and i want to repeat X times a
> specific action. Any idea welcome...

I'm a beginner myself, but I think it would be something like this:

do_n_times(0):- !.
do_n_times(N):-
%do actions,
NewN is N-1,
do_n_times(NewN).

--
"Don't worry about people stealing your ideas. If your ideas are any
good, you'll have to ram them down people's throats."
-- Howard Aiken

.



Relevant Pages

  • Re: for loop in prolog
    ... NewValue is Start+Inc, ... > How could i implement a for loop in prolog. ... Prev by Date: ...
    (comp.lang.prolog)
  • for loop in prolog
    ... How could i implement a for loop in prolog. ... example that i have an integer variable X and i want to repeat X ... Prev by Date: ...
    (comp.lang.prolog)
  • Re: Non-recursive mod problem.
    ... Ok so what's happened is that I caught prolog in a loop because it was ... The only thing I want to ask now is why prolog chooses to increment Q ... goal so the last variable bound is Q so that's what gets ... Prev by Date: ...
    (comp.lang.prolog)
  • Number of days in a month
    ... I'm new to Prolog and writing a little project. ... you'll have to ram them down people's throats." ... Prev by Date: ...
    (comp.lang.prolog)
  • Re: Process notification
    ... As you see from prev. ... posts there is no obsolute user mode solution on how ... and then immidiatly terminated - your "monitoring loop" may not detect it. ... Vladimir ...
    (microsoft.public.win32.programmer.kernel)