Multiway Selection Encyclopedia Article

Multiway Selection

The following sections of this BookRags Literature Study Guide is offprint from Gale's For Students Series: Presenting Analysis, Context, and Criticism on Commonly Studied Works: Introduction, Author Biography, Plot Summary, Characters, Themes, Style, Historical Context, Critical Overview, Criticism and Critical Essays, Media Adaptations, Topics for Further Study, Compare & Contrast, What Do I Read Next?, For Further Study, and Sources.

(c)1998-2002; (c)2002 by Gale. Gale is an imprint of The Gale Group, Inc., a division of Thomson Learning, Inc. Gale and Design and Thomson Learning are trademarks used herein under license.

The following sections, if they exist, are offprint from Beacham's Encyclopedia of Popular Fiction: "Social Concerns", "Thematic Overview", "Techniques", "Literary Precedents", "Key Questions", "Related Titles", "Adaptations", "Related Web Sites". (c)1994-2005, by Walton Beacham.

The following sections, if they exist, are offprint from Beacham's Guide to Literature for Young Adults: "About the Author", "Overview", "Setting", "Literary Qualities", "Social Sensitivity", "Topics for Discussion", "Ideas for Reports and Papers". (c)1994-2005, by Walton Beacham.

All other sections in this Literature Study Guide are owned and copyrighted by BookRags, Inc.

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:

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.