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 ?

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