You should avoid legacy versions of for, and use the most
modern format which uses curly braces. Below is explained the reason.
ObjectScript has several control flow statements with constructs as
if, else, for, while and
do..while. But there also exist legacy versions of
if, else and for. The main difference
is that the legacy versions don't use curly braces to separate the flow
control from the code to execute; for instance:
// Newer version
for condition {
do ..firstThing()
do ..secondThing()
}
// Older version
for variable=forparameter,... command
It is possible to associate one codition with several statements, but all them need to be on the same line. This is the first reason why such statements should be avoided (clarity); another reason is that legacy versions can lead to several traps.
If you come from another C-style language, you may be used to write:
for variable=forparameter
do ..something()
However, this will not do what you think it does; as mentioned above, if you are using a legacy control flow statement, the statements executed if the condition is met need to be on the same line.
What the code above essentially means is that while the FOR
statement is executed and the condition evaluated, no statements
are associated to it. Therefore, the code above will execute do
..something() one time regardless of the loop flow.