Rock U - Lava - For Statement
Transcribed Video Content
Okay. So let's now look at for loops and how we can use for loops to, run through a list of different things. Okay. So let's just say that we were given this variable called campuses and that campuses is basically an array. So it's basically a collection of different values.
And we wanna run through each of these items and print out their values. Okay. So kind of a fancy name for that is we're gonna iterate over this array. We're gonna go through it one at a time and present its values. Okay.
So we have a little bit of HTML here. So we're using an unordered list. So all HTML tags have an end tag except when they don't. There's a few that break that rule. But for the most part, they all have an end tag.
And so we're starting our list here and then we're gonna take, the variable that we were given, campuses. So this variable here ties into the variable that we're given. We're gonna say for each campus in campuses, so we create this variable for the the one that we're currently on. And we're just gonna kinda circle through this until we run out of campuses. And we're just gonna print out the campus name.
So now we'll print out ordered, unordered list of the campus names. So you can kind of picture this if you're not, , familiar with the for statement. It's kind of you have a stack of baseball cards and you're just kind of flipping through them one at a time and we're printing off the name. So this for statement takes care of just making sure each one gets a a chance to come through and whatever, that one is, we're just gonna do what this one line item here is. And you can have, , lots of different lines in here.
You can be printing the campus name. You can if it had other properties or attributes you wanna display, you could do that. You could have if statements within your for statements. That's looking at, , if the name is Sun City, do this. If it's Gilbert, do that.
So you can have a lot of other Lava within these tags, but it allows you just to kind of iterate or go through one at a time items in an array. And as usual, hit the, lava page for more information and there's some specific, power tools for the four tag that in some cases can help save you some time.