Short hand syntax can only be used when at least one of the variables in the left side of := is newly declared.
The value of a constant should be known at compile time.
Go is strongly typed language. So, mixing type during assignment is not allowed.
myString
is alias of string
, Go does not allow to assign string
type variable into myString
type variable.Constant does not have a type. They can provide a type on the fly depending on the context.
First line of every go source file should bepackage packagename
which indicate that this source file belong to which pakage.
Source files belonging to a package should be placed in separate folders of their own. It is a convention in Go to name this folder with the same name of the package.
The init function should not have any return type and should not have any parameters.
The init function cannot be called explicitly in our source code.
The init function can be used to perform initialisation tasks and can also be used to verify the correctness of the program before the execution starts.
A package will be initialised only once even if it is imported from multiple packages.
rectLen
and rectWidth
are initialized then.if
structure:if-else
statement:if - else if - else
chain:if
variant:for
loop structure:break
continue
switch true
and it will behave like if - else if
chain.fallthrough
statement is used to transfer control to the first statement of the case that is present immediately after the case which has been executed.fallthrough
should be the last statement in a case. If it present somewhere in the middle, the compiler will throw error fallthrough statement out of place