Go Language Syntax Overview

Syntax overview
Basically C-like with reversed types and declarations, plus keywords to introduce each type of declaration.
Example:
var a int
var b, c *int // note difference from C
var d []int
type S struct { a, b int }

Basic control structures are familiar:
if a == b { return true } else { return false }
for i = 0; i [...]

Syntax overview

Basically C-like with reversed types and declarations, plus keywords to introduce each type of declaration.

Example:

var a int

var b, c *int // note difference from C

var d []int

type S struct { a, b int }

Basic control structures are familiar:

if a == b { return true } else { return false }

for i = 0; i < 10; i++ { … }

Note: no parentheses, but braces required.

Semicolons

Semicolons separate (not terminate) statements but:

semis never required at top (global) level

semis not required after closing ) of declaration list

semis not required after } (unless part of expr)

Thus no semis needed in this program:

package main

const three = 3

var i int = three

func main()

{

fmt.Printf(”%d\n”, i)

}

However, implicit empty statement allows you to use semicolons the same way as in C if you want.

No related posts.

Leave Your Response

* Name, Email, Comment are Required