Swift

Swift

Made by DeepSource

Unused control flow label should be removed SW-W1010

Bug risk
Minor
Autofix

Unused control flow labels in Swift should be removed as they can clutter the code and make it harder to read and understand. Control flow labels are used to specify which loop or conditional statement to break or continue when there are multiple nested loops or conditional statements. However, if a label is not used, it should be removed to avoid unnecessary complexity and confusion.

Having unused control flow labels can also lead to potential bugs when modifying the code, as developers may mistakenly use the wrong label or forget to update it when refactoring the code. Removing unused labels can make the code more maintainable and less error-prone.

Bad Practice

outerLoop: for i in 0..<10 {
    innerLoop: for j in 0..<10 {
        if i == 5 && j == 5 {
            break outerLoop // Unused control flow label
        }
    }
}

Recommended

for i in 0..<10 {
    for j in 0..<10 {
        if i == 5 && j == 5 {
            break
        }
    }
}