Page 269 - Computer_Science_F5
P. 269
Computer Science Control structures Selection control structure
If there is any repetition or condition made C++ programming language uses
within the program, the order of execution selection or decision control structure
should change based on condition and to fulfill a certain condition. This occurs
repetition. Control structure shows how when the sequence of instructions is
FOR ONLINE READING ONLY
execution of data flow within a program determined through the condition. In a
step-by-step. It also simplifies ways of selection control structure, execution
solving problems within a program by takes place when the condition is
avoiding typing many lines of code. There satisfied whereby one side is executed
are three types of control structures used in when the condition is true, and another
C++ programming languages: Sequential, side is executed when the condition is
selection or decision, and iteration or false. Consider a program to register
looping control structure. citizens for presidential voting. The
program will prompt a citizen to enter
Sequential control structure their ages and then check if the age is
Sequential control structure explains greater than 18. Then, registration form
step-by-step the execution of data will open; otherwise, the form will not
within a program. It defines how data open.
is executed sequentially by considering
the order provided by the program. The There are two types of decision
program conducts different series of control structure, namely If statement,
data flow from top to down by creating and Switch-case statement in C++
data link and dependency. Sequential programming language.
structure controls data reading, writing,
arithmetic calculation, assignment of (a) If statement
variables, etc. Figure 4.37 shows a flow If statement is the type of decision control
chart of a sequence control structure. structure used to test the logical flow
of statement execution and determine
whether it is true or false. If statement
Statement 1 involves IF…THEN, IF …ELSE and
Nested IF statement.
IF….THEN
Statement 2
If there is only one option to be tested in
your program, you can use IF….. THEN
Statement 3 statement to test your condition.
IF….THEN displays the result of the
Figure 4.37: Sequential control structure given option when the condition is
260
for Advanced Secondary Schools
Computer Science Form 5.indd 260 23/07/2024 12:34

