% for statement from T Van Le 92 for(I,I,N):-I =< N. for(I,M,N):-M < N, M1 is M+1, for(I,M1,N). for(I,N):-for(I,1,N). % interesting examples of searches - pythagorean triples, 4 square make an integer and so on. sample(N):-for(I,1,N), for(J,1,I), for(K,1,J),print([I,J,K]). pyth(N):-for(I,N), I1 is I+1, for(J,I), for(K,I1,N), K*K=:=I*I+J*J, print([J,I,K]). isqrt(N,Sqrt):-for(I,1,N), I*I>N,!, Sqrt is I-1. lagrange(N):-isqrt(N,L), I1 is N - L*L, for(I,0,I1), J1 is I1 - I*I, for(J,I,J1), K1 is J1 - J*J, for(K,J,K1), N=:=I*I+J*J+K*K+L*L,print,print([I,J,K,L]).