DEV Community

Cover image for Golang Statements You Need to Know
Darpan Vithani for Canopas Software

Posted on

Golang Statements You Need to Know

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.

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay