"renojim" wrote:"TheEndless" wrote:"NewManLiving" wrote:
Is there a continue or a loop
Statement that I missed as well. Now that would save you a bunch of if statements
No "continue" that I'm aware of.
^ Would be really nice to have!
"TheEndless" wrote:"renojim" wrote:"TheEndless" wrote:
No "continue" that I'm aware of.
^ Would be really nice to have!
While we're at it, a "switch" (or "select" to stick with the VBScript-like nomenclature) statement would be awesome to have as well!
for i = 1 to 1000though why won't you just
...
if condition then goto continue
...
continue:
end for
for i = 1 to 1000With GOTO one can pop out of multiple loops - something that ordinary break/continue won't do.
...
if not condition:
...
end if
end for
if i < 4:
if i < 2:
if i < 1:
... '0
else:
... '1
endif
else:
if i < 3:
... '2
else:
... '3
endif
endif
else:
if i < 6:
if i < 5:
... '4
else:
... '5
endif
else:
if i < 7:
... '6
else:
... '7+
endif
endif
endif
"EnTerr" wrote:
Continue is easy to emulate with Goto:
"EnTerr" wrote:
Emulating switch/select is more complicated but there are options: obviously easiest is IF ... ELSEIF ... ELSEIF... ELSE... ENDIF.
"TheEndless" wrote:"EnTerr" wrote:
Continue is easy to emulate with Goto:
[velociraptor cutout, http://xkcd.com/292/]
Of course there are options, but if you read the original post that started the conversation, the whole reason "continue" was brought up was to avoid having to use a ton of nested if/elseif/endif blocks.
switch (true) {
case $x: ...
case ($y > 10): ...
case (rand(1,10) < 3): ...
}
"EnTerr" wrote:
Continue typically it is replaced with a single if not ... end if. Off hand i cannot think of example where "a ton of nested if/elseif/endif blocks" will be needed for that, can you?
while something
if first then continue
number(1)
if second then continue
number(2)
if third then continue
number(3)
' etc
end while
while something
if not first then
number(1)
if not second then
number(2)
if not third then
number(3)
' etc
end if
end if
end if
end while
"RokuMarkn" wrote:"EnTerr" wrote:Yes:
Continue typically it is replaced with a single if not ... end if. Off hand i cannot think of example where "a ton of nested if/elseif/endif blocks" will be needed for that, can you?
[cut]
That's the main purpose of continue, to avoid this style of coding where you've got to tilt your head 45 degrees to read the code.
while something
if first then goto continue
number(1)
if second then goto continue
number(2)
if third then goto continue
number(3)
' etc
continue:
end while
I do not know when it was introduced, but the current Brightscript reference lists "CONTINUE FOR" and "CONTINUE WHILE" statements. (With oddly no mention of "BREAK".)
https://developer.roku.com/docs/references/brightscript/language/program-statements.md
There's no break, but there is "exit while". Are you saying that break is supported?
This is a ten year old thread, so a lot has changed.