Skip to content

Commit

Permalink
Merge pull request #56 from a8m/codingsince1985-patch-1
Browse files Browse the repository at this point in the history
for loop control using break/continue and label
  • Loading branch information
a8m committed Feb 7, 2019
2 parents 61194f6 + 91c0ed6 commit 86740f0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,34 @@ func main() {
}
for { // you can omit the condition ~ while (true)
}

// use break/continue on current loop
// use break/continue with label on outer loop
here:
for i := 0; i < 2; i++ {
for j := i + 1; j < 3; j++ {
if i == 0 {
continue here
}
fmt.Println(j)
if j == 2 {
break
}
}
}

there:
for i := 0; i < 2; i++ {
for j := i + 1; j < 3; j++ {
if j == 1 {
continue
}
fmt.Println(j)
if j == 2 {
break there
}
}
}
```

### Switch
Expand Down

0 comments on commit 86740f0

Please sign in to comment.