Nested Control Structures

Nested Control Structures - COP 3223: C Programming Spring...

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

View Full Document Right Arrow Icon
COP 3223: C Programming (Nested Control Structures ) Page 1 © Dr. Mark J. Llewellyn COP 3223: C Programming Spring 2009 Nested Control Structures School of Electrical Engineering and Computer Science University of Central Florida Instructor : Dr. Mark Llewellyn markl@cs.ucf.edu 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 DocumentRight Arrow Icon
COP 3223: C Programming (Nested Control Structures ) Page 2 © Dr. Mark J. Llewellyn An Aside On Boolean Values In C The C89 standard for the C programming language does not include the Boolean data type. (The C99 standard does, but not all C compilers have yet adopted the C99 standard). A common solution to this problem that has been adopted by many C programmers is to define your own definitions. This can be done in two different ways. I’ll show you the most common way first. Define constants for both true and false as follows: #define TRUE 1 #define FALSE 0 Then to use these values do something like: int flag = FALSE; or int flag = TRUE;
Background image of page 2
COP 3223: C Programming (Nested Control Structures ) Page 3 © Dr. Mark J. Llewellyn
Background image of page 3

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

View Full DocumentRight Arrow Icon
COP 3223: C Programming (Nested Control Structures ) Page 4 © Dr. Mark J. Llewellyn
Background image of page 4
COP 3223: C Programming (Nested Control Structures ) Page 5 © Dr. Mark J. Llewellyn An Aside On Boolean Values In C In the previous example notice that the conditional expression used in the if statement had the form: if (control) rather than if (control == TRUE) The first form is the preferred form because (1) it is more concise and (2) the expression will still work correctly within the normal C environment even if control has a value other than 0 or 1.
Background image of page 5

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

View Full DocumentRight Arrow Icon
COP 3223: C Programming (Nested Control Structures ) Page 6 © Dr. Mark J. Llewellyn An Aside On Boolean Values In C The other way of accomplishing this is to use the typedef statement to define a user defined type that can be used as a synonym for the built-in type it is based on: typedef int Boolean; then declare a variable to be of this newly defined type as in: Boolean control; As the example program on the next page illustrates this technique, which is often combined with the first technique to define a complete definition of a Boolean type (i.e., the definitions for true and false are also used).
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/21/2010 for the course COP 3223 taught by Professor Guha during the Spring '08 term at University of Central Florida.

Page1 / 25

Nested Control Structures - COP 3223: C Programming Spring...

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

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