Write a while loop in R that starts with the number 1 and keeps adding numbers together until the total reaches at least 50. Print the final total.

total <- 0
currentNumber <- 1

while (total < 50) 
{
  total <- total + currentNumber
  currentNumber <- currentNumber + 1
}

print(total)
## [1] 55
  1. Write a function called add_five that takes a number and returns that number plus 5.
add_five <- function(x) {
  return(x + 5)
}
  1. Write a function check_number that takes a number and returns “Positive” if the number is greater than 0, “Negative” if less than 0, and “Zero” if equal to 0.
# 2. Function check_number
check_number <- function(x) {
  if (x > 0) {
    return("Positive")
  } else if (x < 0) {
    return("Negative")
  } else {
    return("Zero")
  }
}
  1. Write a function sum_of_cubes that uses a for loop to calculate the sum of the cubes of numbers from 1 to n.
sum_of_cubes <- function(n) {
  total <- 0
  for (i in 1:n) {
    total <- total + i^3
  }
  return(total)
}
  1. Write a function countdown that uses a while loop to print numbers starting from n down to 1, and then returns “Blast off!”.
countdown <- function(n) {
  while (n >= 1) {
    print(n)
    n <- n - 1
  }
  return("Blast off!")
}