MODULE 2: GO - Basic Syntax: Web Systems and Technologies
MODULE 2: GO - Basic Syntax: Web Systems and Technologies
fmt.Println("Hello, World!")
The individual tokens are:
• fmt
• .
• Println
• (
• "Hello, World!“
• )
Line Separator
• In a Go program, the line separator key is a statement terminator.
That is, individual statements don't need a special separator like “;” in
C. The Go compiler internally places “;” as the statement terminator
to indicate the end of one logical entity.
• For example, take a look at the following statements:
fmt.Println("Hello, World!")
fmt.Println("I am in Go Programming World!")
Comments
• Comments are like helping texts in your Go program and they are
ignored by the compiler. They start with /* and terminates with the
characters */ as shown below:
/* my first program in Go */
Note:
You cannot have comments within comments and they do not occur
within a string or character literals.
Identifiers
• A Go identifier is a name used to identify a variable, function, or any
other user-defined item. An identifier starts with a letter A to Z or a to
z or an underscore _ followed by zero or more letters, underscores,
and digits (0 to 9).
number abc
myName a_123
_temp
Keywords
• The following list shows the reserved words in Go. These reserved
words may not be used as constant or variable or any other identifier
names.
Whitespace in GO
• Whitespace is the term used in Go to describe blanks, tabs, newline
characters, and comments. A line containing only whitespace,
possibly with a comment, is known as a blank line, and a Go compiler
totally ignores it.
• Whitespaces separate one part of a statement from another and
enables the compiler to identify where one element in a statement,
such as int, ends and the next element begins. Therefore, in the
following statement
var age int;
Whitespace in GO
• There must be at least one whitespace character (usually a space)
between int and age for the compiler to be able to distinguish them.
On the other hand, in the following statement:
Valid: x = 20.0
Invalid: 10 = 20
Reference
• Prime Packs. (n.d.). Retrieved from
https://www.tutorialspoint.com/index.htm