Abstract
Like other high-level programming languages, C has the ability to make decisions by comparing values. Two values can be tested for equality, for example, and one block of statements can be executed if the values are equal. Another block of statements, or no statements at all, can be executed if the values aren’t equal. The purpose of such decision-making statements should already be clear from the discussion of pseudocode commands in Chapter 1. Also, we have already used some implementations of the pseudocode IF…THEN…ELSE statement in Chapters 2 and 3 in code for reading files. For instance, in the statements
status=fscanf(infile,…); if (status == EOF) break;
and
infile=fopen(name,“r”);
if (infile == NULL)
printf(“Can’t find file.”); else …
if … statements are used to respond appropriately when the end-of-file mark is found or when the program can’t find a requested file.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Preview
Unable to display preview. Download preview PDF.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 1999 Springer Science+Business Media New York
About this chapter
Cite this chapter
Brooks, D.R. (1999). Selection and Repetition Constructs. In: C Programming: The Essentials for Engineers and Scientists. Undergraduate Texts in Computer Science. Springer, New York, NY. https://doi.org/10.1007/978-1-4612-1484-7_4
Download citation
DOI: https://doi.org/10.1007/978-1-4612-1484-7_4
Publisher Name: Springer, New York, NY
Print ISBN: 978-1-4612-7161-1
Online ISBN: 978-1-4612-1484-7
eBook Packages: Springer Book Archive