Let’s Go ~ A Complete Guide (Part ~ IV)

Himanshu Singh
MindOrks
Published in
2 min readAug 9, 2018

Hey, Welcome to the series Let Go. This is the Part ~ IV of the series. If you have not seen the previous parts, Click Here. Till now we have covered Installation and Basics.
In this part we will cover statements and functions.

The Index for this series is as followed,

  1. Introduction to Go
  2. Go Environment Setup
  3. Go Basics
  4. Control Statement and Functions
  5. Structs
  6. Object Oriented Programming in Go
  7. Concurrency

Control Statements

  • A control statement is a statement that determines whether other statements will be executed.
  • This helps in reducing the lines of code you have to write and also write them intelligently.
  • Categories of statements are, Condition, Unconditional and Loop
  • Lets begin now .

IF-ELSE

  • If is the most common key word used by any programer
  • It specifies that if certain expressions meet a condition then do a following set of task based on the condition.
  • But in Go, if doesn’t need parenthesis(Curly braces for some).
  • Syntax,

GOTO

  • goto is a keyword in Go.
  • It is used to re-route a flow in Go within same code block.
  • It re-routes back to the label
  • Here in the example, label is LOOP

FOR Loop

  • It is used to read data based on some expressions or conditions
  • For loops Works like while loop in general
  • But in Go, for can be used without parenthesis(Curly braces for some of the devs).

Example

  • To create a infinite loop we use ,
for {//the logic to be executed without any limit}

Switch Statement:

  • Switch are more or less like if-else in any general programming language
  • It has a top to bottom approach in execution
  • It stops the execution after it satisfies the expression.
  • To still keep on executing, we use fallthrough after every statement

Example,

Functions

  • We use func keyword define a function in Go.
  • It contains zero, one or more than one arguments, where arguments are actual input supplied at function call.
  • Arguments are separated by ,
  • main() is also a function in Go. Which gets called when
  • Function have return types.In Go we can have multiple return values.

Example,

Variadic functions

  • Variadic functions are a special type of functions in Go.
  • These type of function can take a number of arguments.
  • It takes arguments as (arg ...datatype) .

Example,

Let’s move to , Part ~ V, to move on with the series. See you there !

If you are liking this series, add 👏 and show some love. 💌

Follow me on Facebook, Twitter, Instagram 😃

--

--