Program Control Structures In C - Part 1

Program Control Structures In C - Part 1 - COP 3223 C...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3223: C Programming (Control Structures – Part 1) Page 1 © Dr. Mark J. Llewellyn COP 3223: C Programming Spring 2009 Program Control Structures In C - Part 1 School of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn m[email protected] HEC 236, 407-823-2790 http://www.cs.ucf.edu/courses/cop3223/spr2009/section1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
COP 3223: C Programming (Control Structures – Part 1) Page 2 © Dr. Mark J. Llewellyn Control Structures In C Normally, statements in a program are executed one after the other in the order in which they appear in the code. This is called sequential execution . There are various C statements that we will soon see that enable the programmer to specify that the next statement to be executed may be other than the next on in sequence. This is called transfer of control . Historically speaking, it has been shown that all programs can be constructed in terms of only three types of control structures , namely the sequence structure , the selection structure , and the repetition structure.
Background image of page 2
COP 3223: C Programming (Control Structures – Part 1) Page 3 © Dr. Mark J. Llewellyn Control Structures In C C provides three types of selection structures in form of statements. 1. The if selection statement either performs (i.e., selects) an action if a condition is true or skips the action if the condition is false. This is called a single-selection statement because it selects or ignores a single action. 2. The if…else selection statement performs an action if a condition is true and performs a different action if the condition is false. This is called a double-selection statement because it selects between two different actions. 3. The switch selection statement performs one of many different actions depending on the value of an expression. This is called a multiple-selection statement because it selects among many different actions.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Page 4 © Dr. Mark J. Llewellyn Control Structures In C C provides three types of repetition structures in form of statements (we’ll look at these in the next set of notes). 1. The while repetition statement allows an action to be repeated as long as some condition remains true. This is a “top-tested” repetition statement, which means that the condition is evaluated before the action is executed the first time. If the condition is initially false, the action is not performed even once. 2. The do…while repetition statement allows an action to be repeated as long as some condition remains true. This is a “bottom-tested” repetition statement, which means that the condition is not evaluated until the action is performed the first time. Thus, the action is always performed at least once with this type of repetition statement.
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 30

Program Control Structures In C - Part 1 - COP 3223 C...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online