Golang Statements You Need to Know

Darpan Vithani - Mar 30 '23 - - Dev Community

In GoLang, we use statements to instruct the program to perform a specific task or action. They are written as a sequence of tokens and executed by the Go interpreter or compiler.

Statements in GoLang are classified into various categories. Like...

  • Declaration statements — use to declare variables, constants, and types.
  • Control flow statements — use to control the flow of execution.
  • Function statements — use to define and invoke functions.
  • Advanced statements — more complex statements that deal with advanced Go features.

Understanding the different types of statements and their usage is essential for effective Go programming.

By using the appropriate statements for each task, we can write more efficient and effective code.

Today, we will see some lesser known but useful statements in Golang with real examples.

Note: I skipped some basic statements like declaration statements(var, const, type), control flow statements(if…else, for, switch), as they are simple and easy to understand.

Table of Contents

  • Control flow statements
    • Panic and Recover
    • Goto statements
    • Break and Continue
  • Functional statements
    • Anonymous function
    • Function closures
    • Blank identifier
    • Variadic functions
  • Other statements
    • Type assertions
    • Defer statements
    • Label statements
    • Select statement
  • Conclusion

For detailed explanation with examples, check out Canopas Blog.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player