This course has been updated! We now recommend you take the Basics of Go course.

Check out a free preview of the full Go for JavaScript Developers course:
The "Control Structures Exercise" Lesson is part of the full, Go for JavaScript Developers course featured in this preview video. Here's what you'd learn in this lesson:

Brenna reviews the control structures discussed in this section, then students are instructed to to iterate over a sentence using range, printing letters with odd indices. The blank identifier is introduced.

Get Unlimited Access Now

Transcript from the "Control Structures Exercise" Lesson

[00:00:00]
>> The next exercise we're gonna do is kind of talking a little bit more about for loops. And it lives in the basic syntax exercise 3A mark down file should take about five to seven minutes. So let's hop over to that file and look at what we're gonna be working on.

[00:00:25] So the goals for this exercise, we're gonna practice setting up that basic go file which we're gonna be using throughout the rest of the workshop, declare some variables. And then we're gonna iterate over a collection using both a classic for loop and the range keyword. We'll use some if statements and then you'll might have to troubleshoot some errors that arise.

[00:00:42] And then the file actually has a bottom here some hints. But before we get to that, the directions for this particular exercise, you'll create another file called exercise 3A.go. I'll go ahead and put it in the code directory if you so choose. And in your main function, the first thing you'll do is declare a variable that has the value of a sentence.

[00:01:00] So we're kinda through the example we just did. Iterate over that sentence, and then the kicker here is this number 4. If the index of that letter is an odd number, print that letter to the console. So a couple of hints to get you started, you might need to convert the type that we just ran into.

[00:01:17] And then just so you know the module operator in go, that percent sign behaves the same way as it does in JavaScript. So if you use the module operator, it'll give you back the remainder of that mathematical operation.