Comp 101 Nesting

Nesting

So by now your comfortable with the idea of conditionals but what if we wanted to make them more complex?

That's where nesting comes in! Lets look at an example

let mealSwipes: number = 1000;
if (mealSwipes > 0) {
  if (mealSwipes <= 10) {
    print("Watch out! Running low!);
  }
  if (mealSwipes > 500) {
   print("So many swipes! Why not swipe in a friend?");
  }
  if (mealSwipes > 10 && mealSwipes <= 500) {
   print("Enjoy your meal!");
  }
}

if (mealSwipes <= 0){
  print("Better head to Alpine.");
}