Input loop is part of Short Circuit's Console Program Basics selection.
Task

Read from a text stream either word-by-word or line-by-line until the stream runs out of data.

The stream will have an unknown amount of data on it.




 
class Main
{
  public static Void main ()
  {
    // example of reading by line
    str := "first\nsecond\nthird\nword"
    inputStream := str.in
 
    inputStream.eachLine |Str line|
    {
      echo ("Line is: $line")
    }
 
    // example of reading by word
    str = "first second third word"
    inputStream = str.in
 
    word := inputStream.readStrToken // reads up to but excluding next space
    while (word != null)
    {
      echo ("Word: $word")
      inputStream.readChar // skip over the preceding space!
      word = inputStream.readStrToken
    }
  }
}
 