if x < 0 && err == nil{
result = "Greater"
} else if x == 0 {
result = "Equal"
} else {
result = "Less"
}
if x := 42; x < 0 {
//....
}
fmt.Println(x) //WONT WORK
Like C/Java, but evaluates any simple type and no breaks needed jumps after block fround
//switch dow {
switch dow := rand.Intn(6); dow {
case 1:
//..
case 7:
//..
default:
//..
}
x := -42;
switch {
case x > 0:
result = "Greater"
case x < 0:
result = "Less"
fallthrough //execute everything below too
default:
result = "Equal or Less"
}
for i := 0; i < 10; i++ {
sum += i
}
for i := 0; i < len(colors); i++ {
fmt.Println(colors[i])
}
for i := range colors { //set i to current index
fmt.Println(colors[i])
}
for sum < 1000 {
sum += sum
if sum > 500 {
break
}
}
endofprogram : fmt.Println("start of program")
if sum > 200 {
sum -= sum
goto endofprogram
}