Santosh Shrestha 157 Followers Stay humble. Refresh the page, check Medium ’s site status, or find something interesting to read. Thanks for reading this microblog and subscribe to my YT Channel The Data Singh for constant updates on Python, Interviews, Company Reviews. Working with Constants and iota in Golang by Santosh Shrestha wesionaryTEAM Sign up 500 Apologies, but something went wrong on our end. This will automatically assign unique values to all these constant variables.īy default, it starts the values from 0 and increments the values by 1 with every constant but this is not something we can rely on, so be careful while using Iota. These are just 7 unique values, if you were to create let's say 100 such values you don't have to assign unique values to these constants, you can use iota to get unique values for all these constants. Because it can be used in expressions, it provides a generality beyond that of simple enumerations. The only thing these values should follow is that they have to be unique i.e Monday should not be equal to any other value. Iota - Go Programming Language Wiki Summary Go's iota identifier is used in const declarations to simplify definitions of incrementing numbers. In this situation, values 1,2,3,4,5,6 don't make much sense. ![]() Let's say you want to define 7 constant Monday, Tuesday, Wednesday. import ( 'fmt' 'strconv' ) import 'math'. We can use iota to simulate C’s enum or define constant. It can be used to construct a set of related constants.īasically, Iota is a keyword in Go that helps you to give random values to your constant. Go supports constants of character, string, boolean, and numeric values. ![]() Its value is the index of the respective ConstSpec in that constant declaration, starting at zero. Within a constant declaration, the predeclared identifier iota represents successive untyped integer constants. Like many other languages Go support the concept of enums through the IOTA function.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |