Access over 20 million homework & study documents

search

Prg 210 Selection Control Structures and Repetition Control Structures.

Type

Homework

Rating

Showing Page:
1/8
PRG210
Selection and Repetition Control Structures
University of Phoenix
Mike VanderMeulen
April 28, 2010

Sign up to view the full document!

lock_open Sign Up
Before scripting a program to solve a fastidious problem, it is necessary to have a
comprehensive understanding of the problem and a cautiously laid out approach to solve that
problem. When authoring a program, it is equally important to understand the types of building
blocks that are available such Algorithms, Pseudocode, and Control structures. In this paper I
will solely focus on two of the three main control structures.
Control Structures
The IRCC.edu (2006-2010) website states “for many years program analysts have been
using an approach to program design called “structured design” in which programs are
assembled like building blocks from simple “structures” that define the flow of control to be
followed by a processor when executing the program’s commands. Three simple structures have
been identified that suffice to build a solution to any complex task. These structures are known
as: Sequence, Selection, and Repetition.”
Selection Control Structures
The Selection Control Structure is used for decisions, branching and choosing between
two or more alternative paths. In C, these are the types of selection statements: if, if/else, and
switch.
Simple “IF” Statement: The IF statement supplies a simple way to branch code in
various paths based on a circumstance. When the circumstance is met, a certain piece
of code can be executed; likewise, when the condition is not met, another piece of
code can be executed. The following is an IF statement example:

Sign up to view the full document!

lock_open Sign Up
o IF Love_the Packers = 1
o THEN
o DISPLAY "The user loves the Packers !"
o ELSE
o DISPLAY "The user doesn't love the Packers"
o ENDIF
Null Else Statement: The null ELSE structure is a variation of the simple IF
structure. It is used when a task is performed only when a particular condition is true.
If the condition is false, then no processing will take place and the IF statement will
be bypassed. For example:
o IF student_attendance = part_time
o THEN add 1 to part_time_count
o ENDIF
In this case, the part_time_count field will be altered only if the student’s attendance
pattern is part-time” (Lesley Anne Robertson , 2007, para. Chapter 4 Section 1).
Combined “IF” Statement: The Combined IF statement uses multiple conditions that
are connected by AND/OR. The following is an example:
o IF (Gender==F AND Age<18)
o THEN

Sign up to view the full document!

lock_open Sign Up

Anonymous
Just what I needed…Fantastic!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4