Search⌘ K
AI Features

Exercise 11: for Loops

Explore how to write for loops in R to iterate through vectors and print specific messages for numbers that are multiples of 3, 5, or both. Understand how to use the cat() function for clear output and practice solving problems that apply conditional logic inside loops.

Problem Statement

For each element in the given vector, print foo if it is a multiple of 33, bar if it is a multiple of 55 and foo bar if it’s a multiple of both 33 and 55.

Use the cat() function for printing. Remember to print the number as well as the respective statement!

Input

A testVariable containing the vector of numbers

Output

The element and the attached statement with it.

Sample Input

testVariable -> c(3, 5, 15)

Sample Output

3 foo 5 bar 15 foo bar

Test Yourself

Write your code in the given area. If you get stuck, you can look at the solution.

R
# Write your code here
cat(" ")