Skip to main content

Syntax

Reserved Words

breakdefaultfuncinterfaceselect
casedeferGomapstruct
chanelseGotopackageswitch
constfallthroughifrangetype
continueforimportreturnvar

defer

In Go language, defer statements delay the execution of the function or method or an anonymous method until the nearby functions returns. Or in other words, defer function or method call arguments evaluate instantly, but they execute until the nearby functions returns. You can create a deferred method, or function, or anonymous function by using the defer keyword.

https://www.geeksforgeeks.org/defer-keyword-in-golang

Decision making

  1. if statement - An if statement consists of a boolean expression followed by one or more statements.

  2. if...else statement - An if statement can be followed by an optionalelse statement, which executes when the boolean expression is false.

  3. nested if statement - You can use one if or else if statement inside another if or else if statement(s).

  4. switch statement - A switch statement allows a variable to be tested for equality against a list of values.

    1. Expression Switch − In expression switch, a case contains expressions, which is compared against the value of the switch expression.

    2. Type Switch − In type switch, a case contain type which is compared against the type of a specially annotated switch expression.

  5. select statement - A select statement is similar to switch statement with difference that case statements refers to channel communications.