answersLogoWhite

0


Best Answer

SELECTION CONTROL STRUCTURES AND THEIR USE

A selection control structure is used to make a choice between two or more actions, depending on whether a condition is true or false. This condition is expressed with one of the relational operators like less than, greater than, equal to (<,>,=,<>,)etc. Adding selection structures makes the program a lot more structured and also gives the programmer a lot of flexibility. There are mainly four different kinds of selection control structures.

1. Simple selection

2. Simple selection with null false branch

3. Combined selection
4. Nested selection

Let us go through the control structures one by one relating them to real life examples.

1>Simple selection (Simple If statement):

Simple selection occurs when a choice is made between two alternate paths, depending on the result of a condition being true or false. The important keywords used are IF, THEN, ELSE and ENDIF.Let us take the example of a city where we want to count the sex ratio. For that we need to calculate the number of males and females. A pseudocode to solve the problem using a simple selection structure would be as follows

IF Gender = "M"

THEN

Increase Male-Count by one

ELSE

Increase Female-Count by one

ENDIF

2. Simple Selection with Null False Branch (null ELSE statement):

These kind of selection structures are used when we a task is performed only when a particular condition is true. If the mentioned condition is false, then there is no execution or processing and the IF statement is skipped or bypassed. The ELSEclause is not used. Thus the selection is between executing or bypassing an action. The important keywords used are IF, THEN, ELSE and ENDIF.

Let us take an example where we want to count the number of adults in a city. A pseudocode to solve the problem using a simple selection with null false branch would be as follows

IF AGE > 18

THEN

Increase Adult Count by one

ENDIF

3. Combined Selection(combined IF statement):

A combined IFstatement is one that contains multiple conditions, each connected with the logical operators AND or OR.

If the connector AND is used to combine two conditions, then both conditions must be true for the combined condition to be true.

First let us take an example of combined selection using AND. Say we want to count the number of females above the age of 18.The pseudocode would be

IF Age > 18 AND Gender = "F"

THEN

Increase Female-Adult-Count by one

ENDIF

If the connector ORis used to combine two conditions, then only one of the conditions needs to be true for the combined condition to be considered true.

Say we want to determine the tickets that can be priced at half rate for children and senior people. The pseudocode would be

IF Age < 12 OR Age > 65

THEN

Add 1 to Half-Price-Count

ENDIF

4. Nested Selection (nested IF statement)

A nested selection occurs when the word IF appears more than once within an IFstatement. A nested selection (IF) occurs when either the true of false branch of one If has another IF statement embedded within it.

This kind of structure is used when there are multiple conditions to choose from. For example while calculating tax the tax rate varies according to the gross salary.A simple pseudocode to count number of male and female adults will be

IF Age > 18

IF Gender = "F"

THEN

Increase Female-Adult-Count by one

ELSEIF Gender = "M"

THEN

Increase Male-Adult-Count by one

ENDIF

ENDIF

REPITITION CONTROL STRUCTURES AND THEIR USE

This type of control structures specify a block of one or more statements that are repeatedly executed until a condition is satisfied. These are also called iteration control structures. There are three different ways that a set of instructions can be repeated, and each way is determined by where the decision to repeat is placed:

- at the beginning of the loop (leading decision loop)

- at the end of the loop (trailing decision loop)

- a counted number of times (counted loop)

1. Leading Decision Loop:

In such loops the testing of the condition is at the beginning of the loop. Examples are DOWHILE loops. The only way to terminate the loop is to render the DO WHILE loop false. Consider a program to sell tickets. The program should sell tickets while there are tickets available. In such types of loops Leading Decision loops can be used to sell tickets until tickets are 0 which can be used as the termination statement.

2. Trailing Decision Loop:

In such structures the testing of condition is done at end of loop except that the logic to keep on repeating is same as in case of other repetition structures. REPEAT…UNTIL is an example of trailing decision loop. In trailing loops the statements are executed at least once before the condition is tested. These loops are sued in almost all kinds of computer program for e.g to print student records, to continue taking input until a certain limit, etc.

3. Counted Loop:

These are also known as DO or FOR loops. In such kind of repetition structures the programmer knows in advance the exact number of loop iterations. The loop execution is controlled by an important variable called the loop index. Say a programmer wants to input the salary record for 20 individuals. He will give the counted loops a high priority because he knows hp many times he wants to repeats the loop.

Finally we can conclude that selection control structures and repetition control structures find their use in almost any application. Using them wisely and judiciously depends on the person who is going to use these loops. Proper implementation of loop structures can reduce program complexity and cost a lot.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Selection and Repetition Control Structures Prepare a 3 to4 page paper that addresses the following- Selection Control Structures Explain how selection control structures increase the usefulness and?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How does selection control structures increase the usefulness of a computer program?

A computer is a computer more can happen to it


Is 'c' a structured language?

Yes, in C, you can use the standard programming structures (sequence, selection, repetition).


Why c is call structured programming?

Because you can use programming structures, namely: sequence, selection (if, switch) and repetition (while, for, do-while)


What does natural selection predict about mimicry camoflauge homologous structures and vestigial structures?

a


What are the 3 primitive logic structures?

The three primitive logic structures in programming are selection, loop and sequence. Any algorithm can be written using just these three structures.


why are structures not removed by natural selection?

Vestigial structures do not harm the organism. Nature selects against only harmful traits.


What are the three selection structures available in C plus plus?

if while switch


Charles Darwin concluded that in similar environments around the world could produce similar structures in unrelated species?

Natural selection


Did exchange method is possible in sorting algorithms in data structures?

yes....exchange checking are: bubble sort, selection sort , quick sort


What are the 4 types of natural selection?

Fossil Records Similarities in Body Structure Similarities in DNA Similarities in Early Development


What has the author Martin Bachmann written?

Martin Bachmann has written: 'Der barocke Wiederaufbau: bauhistorische Untersuchungen in der Durlacher Altstadt' -- subject(s): SEL Library selection, Architektur 'Tarabya' -- subject(s): Ambassadors, History, Buildings, structures, Homes and haunts, Description and travel 'Der barocke Wiederaufbau' -- subject(s): Buildings, structures, History


How are vestigial structures not removed by natural selection?

Yes, because vestigial structures can be harmful. For example, some humans are now born without an appendix which ensures they will not be killed via appendicitis. Having a smaller expression of a vestigial structure, like having a smaller appendix, saves on the energy wasted in maintaining an unneeded structure.