How to .go : For
Tags: go, replit, programming, tutorial
Published: 2023-02-24 07:06:10

## Introduction

Hey people,

have you ever heard about Go? Well, let me tell you that Go is amazing! If you don't know a lot of things about Go, here are some bullet points : 

- statically typed, compiled high-level programming language

- Designed at Google

- syntactically similar to C, but with memory safety, garbage collection, structural typing, and CSP-style concurrency

- It has a mascot which is really cool

- It's very very fast

## Go on Replit

Replit has hundreds of programming languages templates, and when I say hundreds I mean it. There are some Go related templates, for example these : 

- Go 

- Go HTTP Template

- Beego

- Discordgo

These are some popular templates, I actually made Beego! Starting using Go in Replit is very simple, if you don't have account, follow these steps : 

1. Go to https://join.replit.com/Hugo (it's my code :smile:)
2. Fill in all the details
3. Once you've filled all the details verify your accounts by email
4. Once your account is verified click on the create button and search Go
5. Select Go, put a title to your repl and click on the Create Repl button

Once you've clicked on the Create Repl button you will enter to the workspace, where you will be able to start coding!

## For

If you've been coding for sometime, I'm sure that you might have come across the for loops in Python. This is a code example using the for loops : 

```python
languages = ["go", "css", "c++"]
for x in languages:
  print(x)
```

For loops are very simple in Python, but I didn't find them so simple in Go! Here is a simple code example of a For loop I did with Go : 

```go
package main

import (
	"fmt"
)

func main() {
  i := 3

  for i <= 5{
    fmt.Println("Hello world!")
    i = i + 1
  }
}
```

Let's look through the code so you can understand For loops! As always we start with the basic stuff : 

```go
package main

import (
  "fmt"
)

function main() {
  //blah blah blah
}
```

The first thing I do is declare a variable named i, and I give it a value of 3. You might be asking yourself why I wrote a colon and an equals instead of an equal. well, this is why :

- Colon + Equals is for declaration + assignment
- Equals is for declaration
 
After doing all that, this is our code : 

```go
package main

import (
  "fmt"
)

function main() {
  i := 3
}
```

And now the real thing starts! First I start the for arguments, so I say : 

```go
function main() {
  i := 3
  
  for i <= 5{
    //blah blah blah
  }
}
```

Now you might be asking yourself what <= means. In Go it means less than or equal to. After this, you now put the easy stuff inside the for loop. My first line inside the for loop prints Hello world!, and the other one adds 1 to i, and when i is equal to 5 it will stop printing Hello world! 

This was the final code :

```go
package main

import (
	"fmt"
)

func main() {
  i := 3

  for i <= 5{
    fmt.Println("Hello world!")
    i = i + 1
  }
}
```

And this was the result of the console : 

```
Hello world!
Hello world!
Hello world!
```

## The end :wave:

If you've reached this part, congrats. This is the end! Don't forget to follow me on : 

- [Replit](https://replit.com/@Hugo)
- [Use my Replit Join Link](https://join.replit.com/Hugo)
- [Youtube](https://wyoutube.com/@Hugoonreplit)
- [Github](https://github.com/Hugoonreplit)
- [Lichess](https://lichess.org/@/urias6710)

If you want to play with me on Lichess, challenge me to a match!