products([
["Banana",1],
["Apple",2],
["Pinapple",2.5]
]).
!start.
+!start : products(List) <-
.length(List,LLenght);
-+listSize(0);
while(listSize(Sz) & Sz < LLenght)
{
.random(Y);
.nth(Sz,List,Item);
.nth(0,Item,Name);
.nth(1,Item,Price);
.print("Product(",Sz,"): ",Name," $",Price);
-+listSize(Sz+1);
}.
Another way is using "member" internal action which returns with each item of a list (which can be seen as a register if it is a two dimensions array):
products([
["Banana",1],
["Apple",2],
["Pinapple",2.5]
]).
!start.
+!start : products(List) <-
for (.member(Item,List)){
.random(Y);
.nth(0,Item,Name);
.nth(1,Item,Price);
.print("Product: ",Name," $",Price);
}.