The analyzer has detected a potential error of not using the loop counter in one of the loops when writing nested for loops.
The example:
func BubbleSort(values []int) {
for i := 0; i < len(values); i++ {
for j := 0; j < len(values) - 1; j++ {
if values[i] > values[i + 1] {
values[i], values[i + 1] = values[i + 1], values[i]
}
}
}
}
An error occurred when implementing the bubble sort algorithm: the j counter is not used within the loop.
The fixed code:
func BubbleSort(values []int) {
for i := 0; i < len(values); i++ {
for j := 0; j < len(values) - 1; j++ {
if values[i] > values[j + 1] {
values[i], values[j + 1] = values[j + 1], values[i]
}
}
}
}
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders:
Take
a chance!