Forgot your password?  

Not What You Meant?  There are 12 definitions for Selection.

Multiway Selection | Research & Encyclopedia Articles

Print-Friendly   Order the PDF version   Order the RTF version
About 1 pages (338 words)
Selection algorithm Summary

 


Multiway Selection

Multiway selection is a term that is relevant to programming in computer science. Languages such as C++ employ multiway selection. Specifically, multiway selection is a style of code writing that allows the testing of a variable against a list of possible values. The different values will affect the variable in different ways. Thus, multiway selection allows a programmer to assess the influence of values on the desirable or undesirable function of a variable, and to program in various options for a given variable.

Multiway selection operates by the use of what is termed the switch statement. A switch statement is what permits many possibilities to be presented, along with the criteria for their selection.

The following is an example of multiway selection:

  • switch (lottery win) {
  • case (10): <tab>cout << "Get 5 more lottery tickets"<< endl;
  • break;
  • case (25): <tab>cout << "Get expensive meal in a restaurant" << endl;
  • break;
  • case (100): <tab>cout << "Weekend at local Bed and Breakfast" << endl;
  • break;
  • case (1000): <tab>cout << "Cruise around the world" << endl;
  • break;
  • case (10000): <tab>cout << "Stop writing and retire" << endl;
  • break;
  • default: <tab>cout << "Put winnings in the bank." << endl;
  • } // end of switch

As illustrated above, a multiway selection invokes a default action as well as a number of actions that are dependent on the changeable nature of the variable (in this case the size of the lottery winning). In a real case, the computer would look at the value of the data point and then jump to appropriate case in the switch statement. After executing the 'cout' statement a 'break' statement would be encountered. The computer would then jump to the end of the switch statement. If the data point does not match any of the listed cases, the default clause would be invoked, if present. A default condition is not mandatory. But it is often useful.

The multiway selection builds more flexibility into a program. This is particularly important when the variable is inherently complex in its behavior. Invoking a single option for a variable that is capable of multiple behaviors would be inappropriate.

This is the complete article, containing 338 words (approx. 1 page at 300 words per page).

Ask any question on Selection algorithm and get it answered FAST!
Answer questions in BookRags Q&A and earn points toward
discounted or even FREE Study Guides and other BookRags products!
Learn more about BookRags Q&A
Copyrights
Multiway Selection from World of Computer Science. ©2005-2006 Thomson Gale, a part of the Thomson Corporation. All rights reserved.

Join BookRagslearn moreJoin BookRags

Join BookRagslearn moreJoin BookRags