Exercise 10: while Loops
Explore how to implement while loops in R by solving a common programming task. You'll print numbers from 1 to 20 alongside messages for multiples of 3, 5, or both, using the cat() function. This exercise helps you understand loop control and conditional printing in R programming.
We'll cover the following...
We'll cover the following...
Problem Statement
Run a loop from to and for each number, print foo if it is a multiple of , bar if it is a multiple of and foo bar if it’s a multiple of both and .
Use
cat()for printing. Remember to print the number as well as the respective statement!
Sample Output
3 foo 5 bar 6 foo 9 foo 10 bar 12 foo 15 foo bar 18 foo 20 bar
Test Yourself
Write your code in the given area. If you get stuck, you can look at the solution.