Controlling code flow
This section covers areas related to controlling the execution of your code. Using specific constructs such as if-else
and switch
, you can execute code conditionally. Constructs like for
, while
, and repeat
, and help
in executing the same code multiple times which is also known as looping. We will be exploring all these constructs in the following section.
Working with if, if-else, and ifelse
There are several constructs which help us in executing code conditionally. This is especially useful when we don't want to execute a bunch of statements one after the other sequentially but execute the code only when it meets or does not meet specific conditions. The following examples illustrate the same:
> num = 5 > if (num == 5){
Get R Machine Learning By Example 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.