Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
deepak
Visitor

The "next" keyword

I thought that the next keyword was the BrightScript equivalent for, say, Java's continue. But, it turns out that it is equivalent to end for. Why ?

1. Every keyword K, which begins its own scope - function sub, if, while, for - ends with end K. Why an additional synonym for end for ?
2. Does this also mean BrightScript doesn't have anything equivalent for Java's continue ? Like exit for is the equivalent to Java's break ?
0 Kudos
1 REPLY 1
RokuJoel
Binge Watcher

Re: The "next" keyword

Brightscript is more similar to BASIC, where For is always followed by a Next:

for i=0 to 100
print i
next i

for each element in array
?element
next


(notice, you don't reference the variable name in a for each)
However Next is deprecated in favor of End For

for i=0 to 100
print i
end for

for each element in array
print element
end for



There is no continue. There is a goto statement which can jump to labeled code:
sub main()
for i=0 to 100
if i=50 then
goto somewhere
end if
end for
somewhere:
print "i=";i
end sub


Generally, using goto statements is not recommended.

- Joel
0 Kudos