for

BAP Online Manuals : Library Reference : Library by Name : for
Previous: flush_print_buffer
Next: free

6.2.58. for

constructs a for loop

SYNOPSIS

INCLUDE 'prolib.h'
for(1,5,X),
	write(X),nl,
X = 5.

SYNTAX

for(Start,End,Count)(i)(i)(o)

ARGUMENTS

integer(Start) (i) Value to start count from
integer(End) (i) Value which is the last count
integer(Count) (o) will be bound to any integer value between Start and End inclusively

DESCRIPTION

This is a standard prolog predicate. Its has End-Start+1 solutions with Count representing all integers in-between Start and End. You can use the ' = ' predicate as a next.
Its definition is:

PREDICATE for(integer,integer,integer).
for(X,Y,X):-	bound(X),bound(Y).
for(X,Y,Z):-
	X<Y,
	X1 is X+1,
	for(X1,Y,Z).

EXAMPLE

for(1,5,X),
	write(X),nl,
X = 5,			% next(X)
write(done),nl.

ERRORS

No runtime errors.

LAYERS

prolog-process, client-server, object


BAP Online Manuals : Library Reference : Library by Name : for
Previous: flush_print_buffer
Next: free