Exercise

Next, you break it

A possible solution to the previous exercise has been provided for you. The code loops over the linkedin vector and prints out different messages depending on the values of li.

In this exercise, you will use the break and next statements:

  • The break statement abandons the active loop: the remaining code in the loop is skipped and the loop is not iterated over anymore.
  • The next statement skips the remainder of the code in the loop, but continues the iteration.

Instructions

100 XP

Extend the for loop with two new, separate if tests as follows:

  • If the vector element's value exceeds 16, print out "This is ridiculous, I'm outta here!" and have R abandon the for loop (break).
  • If the value is lower than 5, print out "This is too embarrassing!" and fast-forward to the next iteration (next).