Book Image

Learning R for Geospatial Analysis

By : Michael Dorman
Book Image

Learning R for Geospatial Analysis

By: Michael Dorman

Overview of this book

Table of Contents (18 chapters)
Learning R for Geospatial Analysis
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
External Datasets Used in Examples
Cited References
Index

Controlling code execution


So far, all of the code sections we have written were executed once in the same order as they were sent to the command line. However, one of the most important themes in programming is the flow control—operations that are used to control the sequences of our code execution. For example, we may want to induce the execution of a certain code section only if a condition is met (these are called conditional statements), or we may wish to execute a code section several times, over and over again (these are called loops). In this section, you will learn about three flow control commands: two to construct conditional statements and one to construct loops.

Conditioning execution with conditional statements

The purpose of conditional statements is to condition the execution of a given code section. For example, the second expression in the following code section is a conditional statement using the if operator:

> x = 3
> if(x > 2) {print("x is large!")}
[1] "x is...