Traverse from the beginning of a singly-linked list to the end.



See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


implement Command;
 
include "sys.m";
sys: Sys;
 
include "draw.m";
 
include "sh.m";
 
init(nil: ref Draw->Context, nil: list of string)
{
	sys = load Sys Sys->PATH;
 
	l := list of {1, 2, 3, 4, 5};
 
	# the unary 'tl' operator gets the tail of a list
	for (; l != nil; l = tl l)
		sys->print("%d\n", hd l);
		# the unary 'hd' operator gets the head of a list
}