WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: KeithW on September 11, 2020, 02:40:03 PM

Title: Single Line IF Statements
Post by: KeithW on September 11, 2020, 02:40:03 PM
Greetings,

In reading the fine manual I was understanding that the following IF statement syntax should be valid


j=1
k=1
l=1
m=1
n=1
for i = 2 to 6
if array[i,0] == ""  Then array[i,0] = array[j,0]  Else  j = i
if array[i,1] == ""  Then array[i,1] = array[k,1]  Else k = i
if array[i,2] == ""  Then array[i,2] = array[l,2]  Else  l = i
if array[i,3] == ""  Then array[i,3] = array[m,3]  Else m = i
if array[i,4] == ""  Then array[i,4] = array[n,4]  Else  n = i
Next


when the code is executed I get a:  "3074: Expression continues past expected end"

I verified there are no other characters at the end of the IF lines...  is this syntax illegal?

Keith
Title: Re: Single Line IF Statements
Post by: td on September 11, 2020, 03:07:27 PM
No, it is not vaild immediate if statment syntax.  The correct syntax is:

if array[i,0] == ""  Then array[i,0] = array[j,0]
Else  j = i

You can have multiple then or else statements after the initial if-then but each must be on their own line.  Of course, it is usually just better to just use the structured if at that point.
if @true
  <statememt>
  <statement>
else
  <statememt>
  <statement>
endif 
Title: Re: Single Line IF Statements
Post by: KeithW on September 11, 2020, 03:15:27 PM
TD,

At least it was a simple and easy fix... was going by the following at the bottom of the IF .. stuff in the Consolidate WIL Manual right above the  Parameters: discussion...  last example of syntax...

if ... then ... else ... (single statement):

if expression then statement
else statement

misunderstood the ELSE had to be on a separate line.

Thanx,
Keith
Title: Re: Single Line IF Statements
Post by: td on September 12, 2020, 08:34:31 AM
In WIL syntax a statement is not necessarily synonymous with a single line.  Assigning a multi-line string to a variable is another example of a statement that consists of multiple lines.