CHAPTER 4

image

Control Structures

In Chapter 3, you saw an example of a simple function for calculating a person’s body mass index (BMI). The function used logic to determine the person’s risk category. The use of logic, conditional statements, and loops are all inherent in controlling the flow of a program. Although there are many different ways to write conditional statements, and loops, too, for that matter, they all boil down to testing to see if some condition is true or false and then behaving accordingly. A program is nothing more or less than a series of instructions telling a computer what to do. As I have mentioned, R is both functional ...

Get Beginning R: An Introduction to Statistical Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.