Get startedGet started for free

Else if 2.0

You can do anything you want inside if-else constructs. You can even put in another set of conditional statements. Examine the following code chunk:

if (number < 10) {
  if (number < 5) {
    result <- "extra small"
  } else {
    result <- "small"
  }
} else if (number < 100) {
  result <- "medium"
} else {
  result <- "large"
}
print(result)

Have a look at the following statements:

  1. If number is set to 6, "small" gets printed to the console.
  2. If number is set to 100, R prints out "medium".
  3. If number is set to 4, "extra small" gets printed out to the console.
  4. If number is set to 2500, R will generate an error, as result will not be defined.

Select the option that lists all the true statements.

This exercise is part of the course

Intermediate R

View Course

Hands-on interactive exercise

Turn theory into action with one of our interactive exercises

Start Exercise