Hook
More breakout videos from this creator.
Twin make sure you do this so your switch won't melt. I'm finna show you how to make a switch that won't melt. Use something called recursion. We create a function called switch and switch is gonna take in ammo. In this function we're gonna do two things. We gotta print ammo so we know how much ammo we got. And then our return statement, we're gonna call our function switch made and we're gonna do ammo minus one. And we're gonna keep doing this over and over and over making our function call itself. This is called recursion. You see when we run it, our switch starts going crazy and then melts. The reason switches keep melting because you don't have a base case. We gotta tell the program to stop. And this is just when we made a switch with a while loop. And then we have to add a break statement in there in order to exit the loop. Our base case is gonna look like if ammo is equal to zero, then we're gonna return "No More Ammo" and this is gonna stop our program. Remember, if you're gonna slide recurring switch, make sure you have a base case.