Skip to content
Sign upLog in
← Back to Community
Golang Googles C++ Part 5: For Loops
Profile icon
JustAWalrus

Sorry for the long wait, I just don’t have any motivation to do these anymore.

Anyway today we will talk about loops!

What the heck is a loop!?!?!?!!

Umm, well a loop is a snippet of code that keeps on running while a certain condition is true.

Well, what are the kinds of loops?

There is only 1 type in go: a for loop!

Basically, a for loop is a loop you might be used to is a loop that iterates over for something in something else.

But in Go they are different.

In Go a for loop is basically a combo of the loop your used to and a while loop.

So how do they work?

Well let’s look at a basic for loop:

for i := 0; i < 10; i++ { sum += i }

What does this all mean?!
Well we can break it down:

The for is a keyword telling Go that we are making a For loop.

The i := 0 is code that will run before the loop starts. This can be anything.

Then we have a semicolon.

Then i < 10 this is the condition that as long as it is true the loop will keep running.

Another semicolon.

Then i++ This is code that will be repeated every time the code in the loop runs.

Then the brackets you should recognize these from last tutorial.

Anyway that’s it. Again, sorry for the long wait I just haven’t had any motivation lately.

Please upvote for more!

Voters
Profile icon
TusharRawat
Profile icon
zararitz
Profile icon
rileyhead
Profile icon
SarahHeisnoran
Profile icon
ARJPEG
Profile icon
JustAWalrus
Comments
hotnewtop
Profile icon
alex0928

Oh!! thanks for this, apart from your content i have also found one of the best platform to know the best programming language to learn as here were such contents that allowed me learn various language within a week.