Learn Go

Tram Ho

Introduce

In this article, I will rewrite all the knowledge in the process of learning. Get’s go!!!

Contents

Declare variable

We have 3 ways to declare variables:

Note: The declaration method 2 and 3 should be used in a function, and the declaration method 1 is often used to declare a global variable for the entire code.

Variables declared but have no value are:

Use if/else . conditions

If shortened:

Types of data

Data type conversion

The expression T(v) converts the value v to type T.

or

If we declare := like this, the data type will be based on the value of that variable:

Function declaration

A function can take zero or more arguments.

Function Returns 1 value:

The function returns multiple values:

For . loop

For:

Tiếp tục:

While:

If you omit the loop condition, it will loop forever.

Switch

Conditional:

Unconditional:

Defer

Defer is a Go feature that allows you to attach a function to execute after the main function completes.

Stacking defers : are functions called but not yet executed and pushed onto the stack. When the main function completes, functions that haven’t executed it will be run in LIFO (Last-in-First-out) order.

summary

So after 1 day I learned:

  • how to declare variable
  • if/else statement
  • data types
  • function declaration.
  • For . loop
  • Switch
  • Defer, Stacking Defer

Thank you for following my post. Have a nice day. Tks

Share the news now

Source : Viblo