Exercise 8: if/else Statements
Explore how to use if else statements in R to evaluate conditions and print specific results. This lesson helps you understand basic conditional decision-making by testing multiples of numbers and outputting corresponding messages with the cat function.
We'll cover the following...
We'll cover the following...
Problem Statement
Given a number, print foo if the number is a multiple of , bar if it is a multiple of and foo bar if it’s a multiple of both and .
Use
cat()to display your output.
Input
A testVariable containing the number being tested.
Output
The correct statement corresponding to the condition of the number.
Sample Input
45
Sample Output
foo bar
Test Yourself
Write your code in the given area. If you get stuck, you can look at the solution.