CS1053
error break ends a switch case only as its last statement.
#What it means
Switch cases never fall through: each case ends where the next case or default starts. A break as the last statement of a case is accepted (and does nothing). A break anywhere else in a case, for example inside an if, cannot leave the case early.
#Typical cause
- A
breakinside anifin a case, meant to skip the rest of the case.
#How to fix it
Put the rest of the case in an if / else instead, or drop the break. See Conditionals.
#Example
//@chartscript 1
indicator("Mode")
const mode = 2
let s = 0
switch (mode) {
case 1:
s = 1
case 2:
if (close > open) {
break
}
s = 2
}
plot(s)Fixed
//@chartscript 1
indicator("Mode")
const mode = 2
let s = 0
switch (mode) {
case 1:
s = 1
case 2:
if (close <= open) {
s = 2
}
}
plot(s)#Related
- CS2703 — word can only be used inside a loop.