break and continue are keywords that control the loop in many programming languages. The scope of those keywords is at inner most. Here is the example code of C++. In the example code above, break and continue will only affect the inner most loop which deals with the variable j. However, in golang, you can control the scope of break and continue keyword by using labels. Here is the example code. Let’s say there is a library of words and you are querying unique words. For example, when you query the word computer, it should return the first index of READ MORE
Category: Go
This category is about go language
Go Lang – Printf Cheat Sheet
This is a go lang Printf cheat sheet post. Essentially it is very similar to the one in C. Just like the one in C, Printf really prints the string in a formatted way. It is very convenient to have a cheat sheet since I always forget unless I use it frequently. This mainly focuses on examples. print type of variable %T print int type %d This prints integer type. It will perform type check and will give you a warning that type doesn’t match. And of course the result format will be odd. print float %f %f prints floating READ MORE
Go lang – iota and constants
In programming languages such as C++ and Java, there is Enum type which is used frequently. In go language, you can use iota to represent an Enum type. Let’s take a look at a simple example Example Let’s say you want to define variables to represent weekdays. In that case, you probably just want to have integer values for a simple comparison. (You really don’t want to use string to represent the value unless you are printing) Let’s take a look at a version that naively represents the weekdays. Now it will perfectly fine because you can use those variables READ MORE