String Traversal
tags: string-traversal traverse traverse-sequence
Many computations involve processing a string one character at a time. Each character is selected from the string and something is performed to the character. This type of processing is called a string traversal. A while loop or for loop can be used for string traversals.
In general the term traverse means to iterate through the items in a sequence, performing a similar operation on each item. Search is a type of traversal that stops when it finds the element meeting some criteria.
For instance, a function that takes a string as an argument and displays the letters can be implemented as shown below:
|
|
Names can be generated by traversing over the prefixes and concatenating suffix.
|
|