English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

need example of flow control structure (at least 3)?

2007-05-06 15:38:02 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

Flow Control as it relates to programming uses Unconditional , Conditional branching and Looping.

Unconditional branching is a simple GOTO statement. When ever the program encounters this command program execution is directed to the specified location line number or label. This used frequently in proceedural languages to return program execution to the start once the end has been reached.


Specific sections of code may be executed or bypassed either singularly or repetitively based upon the results of a conditional expression. (i.e. X>0)

The Most common is an IF THEN statement

IF X>0 Then
'this code is executed if X is greater than zero
END IF

IF X>0 THen
'this code is executed if X is greater than zero
ELSE
'this code is executed if X is equal to or less than zero
END IF

A SWITCH or SELECT CASE Statement. Program execution is branched to one of more than one CASE or CONDITIONAL result.(This is similar to an IF ELSE THEN)

SELECT n
CASE 1
'This executes if n=1
CASE 2
'This executes if n = 2
CASE 3,4,5
'This executes if n = 3 or 4 or 5
Case n>10
'This executes if n is greater than 10
Case Else
'This execute if none of the above is true
END SELECT


LOOPING:

Looping causes specific section of code to be executed multiple times. This may be done with a FOR NEXT or a DO WHILE statment.

FOR X = 1 to 10
'this code will be executed 10 times
NEXT X

DO
'This code will be executed as long as the
'conditional statment in the WHILE is TRUE
'This code must somehow modify the X And/Or Y
'to eventually cause a condition which will end the loop
WHILE X>Y

2007-05-06 16:50:46 · answer #1 · answered by MarkG 7 · 0 0

Flow control structures are know to have existed for thousands of years. Some built by the Chinese have been in continuous use for over 2,000 years. The Chinese used these structures to divert water to irrigate fields and to actually deposit silt in specific areas so that the channels were not blocked by silt build up. Structures like this required yearly maintenance to remove the accumulated silt.

More modern structures add to these basic principles. In Hawaii, there are numerous flow control structures that have been built to irrigate the Pineapple and sugar cane fields. The purpose of these structures is to divert water into the various canals and to keep them full. When over full, they either dump excess water back into streams or other canals. Among the simplest is a low dam across a shallow stream forcing all of the water to one side to allow it to be easily collect in a canal. This can keep a canal full even with very low flows in a stream.

Another simple device is a series of concrete piers installed in a spillway to slow down the descending water so that it does not cause damage at the bottom of the spillway.

In case you meant C++,check this site for many examples
http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap14.html

2007-05-06 15:41:40 · answer #2 · answered by Gully 2 · 0 1

tricky task. try searching into search engines like google. it might help!

2014-12-08 19:15:46 · answer #3 · answered by Anonymous · 0 0

fedest.com, questions and answers