| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Input in Turing

Page history last edited by Steve Sweeney 15 years, 2 months ago

Input is the process of receiving data from the user.  Most often, this is direct entry via the keyboard, but could also include the mouse, microphone, video camera, or scanner.  In addition, we are sometimes dealing with larger collections of data that the user does not want to input each time the program runs.  For these cases, data is stored in an external file and loaded by the program upon request.

 

The most simple input in Turing uses the "get" command to receive user input from the keyboard.  It does not prompt the user, and simply waits for the user to type data and hit the <enter> key.

 

get firstName

 

In order to avoid confusion and input errors, it is generally necessary to provide some additional information or instruction to the user.  When we ask the user for some input, it is called a "prompt," or "prompting."  The goal is to ensure the user understands what kind of input they are supposed to enter.

 

put "Please enter your first name"

get firstName

 

It is possible to have both the prompt and input appear on the same line using the ".." continuation operator.

 

put "Please enter your first name: " ..

get firstName

 

It is possible to input multiple items using the same get command by separating the variables with commas.  When the user enters their response, each input will be designated by either a space or hitting <enter>.  This requires even more careful prompting to the user, making sure they enter the correct data for each item.

 

put "Please enter your first name, age, and bank balance (in that order)."

put "Hit <enter> after each entry"

get firstName, age, bankBalance

 

As mentioned above, the get statement will "fill" each variable when it sees either a space or an <enter>.  Sometimes, however, we want to user to enter a string that might include spaces (e.g., a full name, a sentence).  In that case, the get command can be modified to input the entire line as a single string.  Keep in mind that this only works for strings!

 

put "Please enter your favourite Shakespeare quotation."

get favQuote : *

 

 

Comments (0)

You don't have permission to comment on this page.