Receiving Input Interactively

Now you will update wordlasso to get its input from the user. To do this, you will change the program to have two modes, depending on whether the user provides a template argument when they run the tool:

  • If the user passes a template as a command-line argument, wordlasso will find and print matches for it, then exit.

  • If the user does not provide a template as a command-line argument, wordlasso will ask for one. Then, if the user enters a template, the program will find and print matches for it and ask for another template. This will continue until the user tells the program to stop.

Start with the second mode: If the user does not provide a template via a command-line argument, ask them for one.

Example 27.14. Accepting ...

Get Swift Programming: The Big Nerd Ranch Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.