RosettaCodeData/Task/Menu/XPL0/menu.xpl0

23 lines
674 B
Plaintext

string 0;
func Menu(List);
int List;
int Size, I, C;
[Size:= List(0);
if Size < 1 then return List(0); \if empty list, return pointer to 0
for I:= 1 to Size-1 do
[IntOut(0, I); Text(0, ": ");
Text(0, List(I)); CrLf(0);
];
CrLf(0);
Text(0, List(Size)); \display prompt
loop [C:= ChIn(0); \buffered keyboard requires Enter key
if C>=^1 & C<=Size-1+^0 then return List(C-^0);
Text(0, "Please enter 1 thru "); IntOut(0, Size-1);
Text(0, ": ");
];
];
Text(0, Menu([5, "fee fie", "huff and puff", "mirror mirror", "tick tock",
"Which phrase is from the Three Little Pigs? "]))