ArticleslgStudy

computer science

Choice (command)

Choice (command) is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Choice (command) rather than just read about it. In short: In computing, choice is a command that allows for batch files to prompt the user to select one item from a set of single-character choices. It is available in a number of operating system command-line shells.

Choice (command) — main illustration
Choice (command) — illustration

Key takeaways

  • Choice (command) belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Choice (command) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Choice (command) from memory before moving on to harder problems.

Reference excerpt

In computing, choice is a command that allows for batch files to prompt the user to select one item from a set of single-character choices. It is available in a number of operating system command-line shells.

History The command was first introduced as an external command (with filenames CHOICE.COM or CHOICE.EXE) with MS-DOS 6.0. It is included in Novell DOS 7 and IBM PC DOS 7.0, and is also available from the command-line shell of some versions of Microsoft Windows, but not under Windows 2000 and Windows XP. It was first made available for Windows in the Windows XP Resource Kit. It has been reintroduced in Windows Server 2003 and is present in later versions. Starting with Windows 2000, the SET command has similar functionality using the /P command-line argument. However this command requires an additional key stroke (hitting ENTER key), which is not required by choice. The choice command has been ported to OS/2, Rexx and Perl. It is also available in Datalight ROM-DOS, FreeDOS, PTS-DOS, and ReactOS. The FreeDOS version was developed by Jim Hall and is licensed under the GPL v2.

Usage The command returns the selected choice as an exit code which is set to the index of the key that the user selects from the list of choices. The first choice in the list returns a value of 1, the second a value of 2, and so forth. If a key is pressed that is not a valid choice, the command will sound a warning beep. If an error condition is detected, an exit code value of 255 will be returned. An exit code value of 0 will be returned if the user presses CTRL+BREAK or CTRL+C. Choice displays the default choices Y and N if used without parameters.

Syntax

DOS CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] ["text"] Arguments:

/C[:]choices Specifies allowable keys. The default is "YN". /T[:]c,nn This defaults choice to "c" after "nn" seconds. text Specifies the prompt string to display. (Quotes are optional). Flags:

/N Specifies not to display the choices and "?" at end of prompt string. /S Specifies that choice keys should be treated as case sensitive.

Microsoft Windows, ReactOS CHOICE [/C [<Choice1><Choice2><…>]] [/N] [/CS] [/T <Timeout> /D <Choice>] [/M <"Text">] Arguments:

/C[:]choices Specifies allowable keys. The default is "YN". (Microsoft Windows restricts valid choice keys to a-z, A-Z, 0-9 and ASCII values of 128 to 254) /T[:]nn This defaults choice to /D after "nn" seconds. Must be specified with default /D. /D[:]c This defaults choice to 'c'. /M text Specifies the prompt string to display. Flags:

/N Specifies not to display the choices and "?" at end of prompt string. /CS Specifies that choice keys should be treated as case sensitive.

Example The batch file below gives the user three choices. The user is directed depending upon his input by evaluating the exit code using the IF ERRORLEVEL command (which tests on "greater or equal"). The selected choice is then printed to the screen using the ECHO command.

Note that the example uses the DOS syntax. This example requires slight adjustments before it applies directly to Windows versions of the CHOICE command. Note that the IF command, when checking the ERRORLEVEL, compares the number and matches if ERRORLEVEL is equal to or higher than that number. Because of this IF ERRORLEVEL comparisons should be done in decrementing order. Note that if the user presses Control-C to escape CHOICE followed by N then the program will continue. The first "Goto end" is needed.

See also List of DOS commands select in bash

References

Further reading Cooper, Jim (2001). Special Edition Using MS-DOS 6.22, Third Edition. Que Publishing. ISBN 978-0789725738. Stanek, William R. (2008). Windows Command-Line Administrator's Pocket Consultant, 2nd Edition. Microsoft Press. ISBN 978-0735622623.

External links

Microsoft TechNet Choice article

Illustrations

Choice (command) illustration

Worked examples

Example 1 — a first encounter with Choice (command)

Start with the simplest possible case. Write down what Choice (command) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Choice (command) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Choice (command) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Choice (command)

In research
Choice (command) appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Choice (command) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Choice (command) is common in secondary-school and first-year university syllabi. It links to neighbouring topics External DOS commands, Microcomputer software, ReactOS commands, so understanding it makes those chapters shorter.
In everyday life
Look for Choice (command) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Choice (command)” →

How to study Choice (command) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Choice (command) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Choice (command) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Choice (command) in simple terms?

In computing, choice is a command that allows for batch files to prompt the user to select one item from a set of single-character choices. It is available in a number of operating system command-line shells.

Why does Choice (command) matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Choice (command)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Choice (command).

Tags

  • External DOS commands
  • Microcomputer software
  • ReactOS commands
  • Windows administration
  • Windows commands

Keep exploring