PDA

View Full Version : How to use if and "=" vs. "==", case command...


buzap
11-19-2009, 09:51 AM
Hi Jeff

in some scripts, I see if mode == reset in others it's if mode = reset .
What is the recommended way of handling this?

While we're at it: Are more complex if statements possible, sort of like
if (mode = reset) AND (saveParameter = 1) ?

And still while we're at it, is there an intelligent way to do this:

case i of
0: #step 0
1: #step 1
2: #step 2


I mean, more intelligent than this workaround:

if i = 0
#step 0
else
if i = 1
#step 1
else
if i = 2
#step 2
endif
endif
endif


best regards
Buzap

Jeff
11-20-2009, 06:14 PM
Unlike other C derived languages = and == are the same.

I decided to do it that way because == looks strange to non-programmers.
But for those that do have experience with other languages == is more
natural. So they both do the same thing. The reason this works
is because you can't do assignment in expressions, you have to use the "set"
statement.

If I had to do it over again I would probably not have done this. We've been gradually moving closer to a "real" language and there have been times
when I wish it behaved more like C/Java than DOS.

You can use complex expressions with most statements. The statement
still begings with a keyword like "set" and often has one or more fix position
arguments like <variableName> then has an arbitrary expression. The expression syntax is like C, you can use parenthesis and the usual operators
&& || ! + - / * % and a few built in functions like rand().

The most common statements that use expressions are Variable to
give it an initial value and set to calculate a value. You can also use
them with if statements for the condition. Your example would be:

if mode = reset && saveParameter = 1

The language does not have a case statement, but you can use "else if"

if x = 1
...something
else if x = 2
....something else
else if x = 3
...something else again
endif