[MUSIC] Let's talk a little bit about Scope. I just mentioned Scope a few times when we were looking at the playground. Keep in mind that a function's body is denoted by open and closing curly braces. These curly braces define the scope of a function, right. So we said the body of a function comes between the curly braces, and that's the scope of the function. And usually we write functions inside of a clause or a struct, which we'll learn about in a different lesson. In this case we're using playground so the enclosing scope of a function is likely to be the whole playground. We just saw an example with nested functions so we have one function inside of another function, so we can refer to those as internal and outer functions. And the internal function's enclosing scope will be the body of the outer function. All right note that nested functions can trap variables inside of their enclosing scope. So let's go take a look at that. All right, so let's look at how this internal function tracked the variable from its enclosing scope. So, we set the enclosing scope of number of moons, the internal function is, the outer function, showed default info of planet nested. This outer function gets passed in a planet, which, instead of the body, will be preferred to as p. Notice here that the function number of moons uses p to get the moons array, if let moons array equals p value for key moons, right? So we didn't pass in p the number of moons function, It just used p from its enclosing scope, which is this outer function. We call that trapping a variable. Let's talk about protecting functions from operating under improper conditions. You may be used to, if you have experience with programming, you may be used to you know checking for improper conditions using if and l statements, right? But there's actually a more convenient way to do this with Swift. We want to make sure that our function doesn't execute under bad conditions, because often times, that means that's not the only case but oftentimes, we run into a situation where an expected value may be nil and at run time, running into nils equals your applicational crash. So we want to protect our function from trying to operate under a nil scenario definitely, but there also may be cases where have non nil, but still bad values or bad conditions to work with. So we can guard against those using a guard statement. The guard statement, we'll see this in text in the playground. It will let us exit the function early, so that we put the guard ceiling at the top of the function and it will contain a conditional to say, hey if such and such a situation is met, go ahead and execute the rest of the function below the guard statement. Otherwise, go into the guard statement and let's get out of this function early or perhaps or perhaps return some kind of default safe and value. This is especially helpful to insure that values that our function is passed or that our function maybe trapping are valid before we go ahead and proceed to execute the rest of our function. Okay, let's go see that in the playground. So here is our same old show info about planet function. This is the show default info version. And I just called it underscore guarded to help keep track of what we're looking at here in the class. Nothing's changed about this function except for at the top of the function, I have this guard statement. So let's look at this. We're going to enhance our info of planet function. To protect against a nil if a dictionary does not have the requested key-value pair. So keep in mind that our planets exist right now as dictionaries. So I'll go into my function, just some helpful print code to let me see what's going on in my console, which function is calling it. But lets focused on this guard statement. So, I say guard and this is very similar syntax to using optional binding. So, I say guard, let moons equal the value for key moons in the dictionary called PR planet. And, if that key value pair exists and the value is not nil. Then moons will get a value and we'll go into the rest of our function. L's go inside this guard statement. Print no information available into our console and return. Notice that this function doesn't have a return type. So what happens when we say return here. We're not going to return a value to the color, we're going to just exit the function and we do that by calling return. Okay, so let's go now and call this guarded function show default of info planet guarded for the planet Venus. And we get no information available. When we created our planet Venus dictionary, lets go look at that. And just to refresher we can jump to definition of a symbol by command clicking on it. So here is Venus and I see Venus has a name and a order, it doesn't have any moons in it. We expect that when we try to get the moon's out of that key value pair will get nil, because there's no moons key, right. We get nil and where's my guard statement, we go into the guard statement, we print out no information available, which is what we see and we exit out of the functions so none of the rest of my function will be executed. [MUSIC]