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


fun main(args: Array<String>) {
    val list = IntRange(1, 50).toList()
 
    // classic traversal:
    for (i in list) { print("%4d ".format(i)); if (i % 10 == 0) println() }
 
    // list iterator:
    list.asReversed().forEach { print("%4d ".format(it)); if (it % 10 == 1) println() }
}