Prolog program to count down from a number using recursion

385 Views Asked by At

Lately I have been learning Prolog and tried to write a program to count down from a number to another given number using recursion but it seems to be not working, the code is as follows:

count_down(L, L) :- !.
count_down(L, H) :-
    write(H), nl,
    Y is H-1,
    count_down(L, Y).

the first rule count_down(L, L) :- !. is to terminate the loop when counting reaches L.

0

There are 0 best solutions below