So basically I am trying to simulate some C code in Prolog.
It is easy to simulate while loop in Prolog Here is the case:
C code:
int a = 1;
Not very different from your prolog_while predicate:
prolog_while(N, A) :-
( N==0 ->
true
;
N1 is N -1,
A1 is A + 1,
prolog_while(N1, A1)
).
But most likely you want the final value of A be available to the caller of this predicate, so you have to return it via an additional argument:
prolog_while(N, A, AFinal) :-
( N==0 ->
AFinal = A
;
N1 is N -1,
A1 is A + 1,
prolog_while(N1, A1, AFinal)
).