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 :
- Go to https://join.replit.com/Hugo (it's my code 😄)
- Fill in all the details
- Once you've filled all the details verify your accounts by email
- Once your account is verified click on the create button and search Go
- 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 :
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 :
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 :
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 :
package main
import (
"fmt"
)
function main() {
i := 3
}
And now the real thing starts! First I start the for arguments, so I say :
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 :
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 👋
If you've reached this part, congrats. This is the end! Don't forget to follow me on :
If you want to play with me on Lichess, challenge me to a match!
Top comments (0)