-
Notifications
You must be signed in to change notification settings - Fork 0
/
loops.pl
50 lines (45 loc) · 858 Bytes
/
loops.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% File with looping facilities
loop(0) :- !.
loop(N) :-
N > 0,
write('The value is: '),
write(N), nl,
M is N-1,
loop(M).
output_values(Last, Last) :-
write(Last),
nl,
!.
output_values(First, Last) :-
First =\= Last,
write(First), nl,
New is First + 1,
output_values(New, Last).
reloop :-
write('Type end to end: '),
read(Word),
write('Input was '),
write(Word),
nl,
(Word=end; reloop).
get_answer(Ans) :-
write('Enter answer to question'), nl,
repeat,
write('answer yes or no: '),
read(Ans),
valid(Ans),
write('Answer is '),
write(Ans), nl.
valid(yes). valid(no).
squares(N1, N2) :-
N1 =:= N2,
X is N1^2,
write(X),
nl,
!.
squares(N1, N2) :-
N1 < N2,
X is N1^2,
write(X), nl,
New is N1 + 1,
squares(New, N2).