At the time of this writing, when you choose a new Go pad it starts you out with some simple code (scroll to the bottom if you want to see it all at once). I'll go through it step by step and then show it in all it's glory at the end.
Right off the bat we can see that a double slash ( // ) is a familiar symbol that signifies the line should be treated as a comment.
Also similar to Java (and also ActionScript 3), we have this name-spacing sort of deal that uses the package keyword. This is basically the directory path in which this file lives.
Putting "package main" means this file is in a folder called main (I think). Although for codepen it doesn't really matter all that much since you're usually just using one file in a codepen (at least I am, anyway).
Then we can import some libraries that we need. To be honest, I'm not really sure what fmt means, and I don't feel like looking it up [ok fine- it's just short for format]. Just know that in order to log text to the console you need to import this library.
We can then log text to the console by using the Println method.
Aside from that weird assignment symbol that uses a colon, for loops don't look all that weird- wait a minute; there are no parentheses in the for statement. That's a little weird... Anyway, here's an example one of of these here for loopers:
That's pretty much all you need to know to understand the snippet of starter code in your coderpad IDE when you switch to Go. You might as well buy a tee-shirt and call yourself a Go developer now. You're welcome. Lol.
Now that you know the ropes you might want to create some functions and call them. Well, just define new functions with the "func" keyword and call them by typing out their name followed by opening and closing parens. Notice that we can call a function before we define it in the code:
The posts on this site are written and maintained by Jim Lynch. About Jim...
Want FREE access to
my daily stock tips
"The Triple Gainers"?
Sign up here!