The selection structure in computer programming gives the program a couple of passage ways to complete a certain task. It separates the code base on different conditions set forth in the coding. This is presented by giving a conditional expression, in which the computer tests conditions in order to know statements to perform. Programmers give the computer guidelines on how to make the proper decision in order to carryout specific task. Selection structure is broken down into three common structures single alternative, dual alternative and case statement. Single-alternative selections, take action on just one branch of the decision. The single-alternative selection structure evaluates a condition and executes a block of code if that condition is true. If the condition is false, then the block of code is ignored. An example of a single-alternative selection structure is the if-then statement. if (average_score < 60)
cout < < "Failing" < < endl;
Dual-alternative is defined as one action to be taken when the tested condition is true and another action to be taken when it is false. The dual-alternative selection structure evaluates a condition and executes one of two possible passage ways paths. If the condition is true, then one block of code is executed. If the condition is false, the other block of code is executed. An example of a dual-alternative selection structure is the if-then-else statement. If (average_score < 60)
>>60 print "Passing"
To make a decision based on the value of a variable we have used the if-then-else statements. If there are multiple values the variable can take on, we have used multiple or nested if-then-else statements. The case selection structure provides multiple alternatives. It inspects a value and chooses the right path of execution that is assigned to that value. For example, a case selection structure could be used to divide the code based on...
Please join StudyMode to read the full document