Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Examples of redundant else usage
------ ⭣ Redundant Else ⭣ ------
if someCondition {
return meh
} else {
let someValue = callSomeFunction()
return someValue
}
----------- ⭣ Fine ⭣ -----------
if someCondition {
return meh
}
let someValue = callSomeFunction()
return someValue
----------- ⭣ Fine ⭣ -----------
if someCondition {
doSomething()
} else {
doSomethingElse()
}
------ ⭣ Redundant Else ⭣ ------
if someCondition {
return
} else {
callSomeFunction()
}
------ ⭣ Redundant Else ⭣ ------
if someCondition {
return meh
} else if someOtherCondition {
let someValue = callSomeFunction()
return someValue
} else {
let someOtherValue = callSomeOtherFunction()
return someOtherValue
}
----------- ⭣ Fine ⭣ -----------
if someCondition {
return meh
}
if someOtherCondition {
let someValue = callSomeFunction()
return someValue
}
let someOtherValue = callSomeOtherFunction()
return someOtherValue
------ ⭣ Redundant Else ⭣ ------
for string in stringsArray {
if string.isEmpty {
continue
} else {
doSomething(with: string)
}
}
----------- ⭣ Fine ⭣ -----------
for string in stringsArray {
if string.isEmpty {
continue
}
doSomething(with: string)
}
------ ⭣ Redundant Else ⭣ ------
for string in stringsArray {
if string.isEmpty {
break
} else {
doSomething(with: string)
}
}
----------- ⭣ Fine ⭣ -----------
for string in stringsArray {
if string.isEmpty {
break
}
doSomething(with: string)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.