Control Structures
if, else if, else
// AND, OR, NOT
if (a == 1 && b == 1) || a == 2 || !b {}
if a {}
else {}
if a == 1 {}
else if a == 2
else {}switch
If using switch inside infinite loops, the break keyword will not be able to be used to end the loop, since it will be used by the switch.
switch choice {
case 1:
...
break
case 2:
...
default:
...
}for-loops
Regular
Infinite loops
Will run until you break.
May not break if a switch is inside. switch
Bounded to a variable's value
Will run until boolVariable is false.
Looping arrays
index and value are arbitrary names.
Looping maps
key and value are arbitrary names.
Last updated