@@ -21,42 +21,42 @@ import "fmt"
2121//
2222// In Golang we have two ways of doing conditional statements: `if/else` and `switch/case`.
2323func main () {
24- var age int
25- var country string
26- fmt .Println ("How old are you?" )
27- fmt .Scanln (& age )
28- fmt .Println ("Where are you from?" )
29- fmt .Scanln (& country )
24+ var age int
25+ var country string
26+ fmt .Println ("How old are you?" )
27+ fmt .Scanln (& age )
28+ fmt .Println ("Where are you from?" )
29+ fmt .Scanln (& country )
3030
31- // One good example is asking your age before visiting some websites.
32- // If the person is a minor, we shouldn't allow him/her to visit the page.
33- // This case is what we call `if/else` statement because it should choose between actions by evaluating expressions as true or false.
34- // It will always execute the first true condition and if no condition is satisfied, it will execute the else.
35- if age >= 21 {
36- // If the provided age is equal or higher to 21, it will print "Welcome!"
37- fmt .Println ("Welcome!" )
38- } else if age >= 18 && country != "US" {
39- // If the provided age is equal or higher to 18 and the user is not from the US it will print the message.
40- fmt .Println ("Quite young but still welcome!" )
41- } else {
42- // If the age is below 18 it will print the following message.
43- fmt .Println ("hmmm... maybe you should not be allowed on here!" )
44- }
31+ // One good example is asking your age before visiting some websites.
32+ // If the person is a minor, we shouldn't allow him/her to visit the page.
33+ // This case is what we call `if/else` statement because it should choose between actions by evaluating expressions as true or false.
34+ // It will always execute the first true condition and if no condition is satisfied, it will execute the else.
35+ if age >= 21 {
36+ // If the provided age is equal or higher to 21, it will print "Welcome!"
37+ fmt .Println ("Welcome!" )
38+ } else if age >= 18 && country != "US" {
39+ // If the provided age is equal or higher to 18 and the user is not from the US it will print the message.
40+ fmt .Println ("Quite young but still welcome!" )
41+ } else {
42+ // If the age is below 18 it will print the following message.
43+ fmt .Println ("hmmm... maybe you should not be allowed on here!" )
44+ }
4545
46- var animal string
47- fmt .Println ("What is your favorite animal?" )
48- fmt .Scanln (& animal )
46+ var animal string
47+ fmt .Println ("What is your favorite animal?" )
48+ fmt .Scanln (& animal )
4949
50- // Sometimes, we do not want to check if something is true or false, but to check if it has a specific value.
51- // This is the best option to use the switch statement.
52- switch animal {
53- case "dog" :
54- fmt .Println ("Dogs bark, right?" )
55- case "cat" :
56- fmt .Println ("Meow!" )
57- case "fish" :
58- fmt .Println ("I've no clue how a fish sounds..." )
59- default :
60- fmt .Println ("Hm... I need to upgrady my animal list..." )
61- }
50+ // Sometimes, we do not want to check if something is true or false, but to check if it has a specific value.
51+ // This is the best option to use the switch statement.
52+ switch animal {
53+ case "dog" :
54+ fmt .Println ("Dogs bark, right?" )
55+ case "cat" :
56+ fmt .Println ("Meow!" )
57+ case "fish" :
58+ fmt .Println ("I've no clue how a fish sounds..." )
59+ default :
60+ fmt .Println ("Hm... I need to upgrady my animal list..." )
61+ }
6262}
0 commit comments