Is there a cleaner way of writing the conditional for case "1", "4", "7"? For this case I want to write to the string "b" only if the string value is not "4".
var b = ""
var c = ""
let s = "4"
switch s {
case "0", "6", "8":
c += "|_|"
case "1", "4", "7":
if s != "4" { b += " |" }
c += " |"
case "2":
c += "|_ "
case "3", "5", "9":
c += " _|"
default:
c += ""
}
I think the whole idea of switch statement is that you don’t use ifs inside. You should probably just create a separate case for “4”. The amount of space saved by putting this conditional isn’t worth obscuring the code IMO.