8. Go - Loops
For Loop with For Clause Format:
for INIT; CONDITION; POST {ACTION}
// can omit INIT if using an already declared variable.
Single Loop:
for i:=1,i<10,i++ {
loop, and increment up to 10
}
Nested Loops:
for i:=1,i<10,i++ {
for i:=1,i<10,i++ {
loop, and increment up to 10
}
}
Infinite Loop:
for {}
For Loop with Single Conditional Statement:
for x == 5 {
loop
}
i := 5
for i <=10 {
loop
}
for a,b := range arrayvariable{
fmt.println(a) // prints index
fmt.println(b) // prints index's value
}
break
// break loops
continue
// voids block below but continue on with loop
example:
for i < 5{
i++
if i == 4{
continue
}
fmt.Println(i)
}
Comments
Post a Comment