Welcome to Synthiam!

Program robots using technologies created from industry experts. EZ-Builder is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.
Get Started

USA
Asked — Edited

Elseif Is Broken

@DJ,

The ElseIf is broken:

The code below never stops !

Code:


$buffer="[123 456 789]"
$len=Length($buffer)
$ix=0
$start=-1
$end=-1
repeatwhile($ix<$len)
$ch=GetCharAt($buffer, $ix)
if ($ch="[")
print("found start")
$start=$ix
elseif ($start>=0 AND $ch="]")
print("found end")
$end=$ix
# break
$ix=$len+1
endif
print("increment ix")
$ix=$ix+1
endrepeatwhile
print($ix)
print($start)
print($end)


if you remove the ElseIf it works as expected.

Code:


$buffer="[123 456 789]"
$len=Length($buffer)
$ix=0
$start=-1
$end=-1
repeatwhile($ix<$len)
$ch=GetCharAt($buffer, $ix)
if ($ch="[")
print("found start")
$start=$ix
endif
if ($start>=0 AND $ch="]")
print("found end")
$end=$ix
# break
$ix=$len+1
endif
print("increment ix")
$ix=$ix+1
endrepeatwhile
print($ix)
print($start)
print($end)


This bug must be recent, i've used before the ElseIf, or did i miss something ?

#18  
An IF or ELSEIF needs an ELSE to finish the clause before the ENDIF.

You can make the ELSE do nothing, but it is still required (at least in EZ-Script. Might be implied in some languages).

Not sure this has always been the case, but it is the difference between the failing and the succeeding cases.

Alan
#20  
@ptp

Yeah, I edited my post to say I am not sure this has always been the case, but is the difference between the working and failing code. Was to point DJ towards cause of bug, not to say scripts were wrong.

Alan
#21  
yes i agree with you.

it seems the problem is when the condition is false and no else is found.

OK:

Code:


print("***Start")
$a=1
repeatwhile($a<=9)
if ($a=1)
Print("1")
ELSEif ($a=2)
Print("2")
ELSEif ($a=3)
Print("3")
ELSEif ($a<10)
Print("less than 10 a="+$a)
endif
$a=$a+1
ENDrepeatwhile
print("***End")


User-inserted image


if you change the condition:

Code:


repeatwhile($a<=10)


it get lost forever:
User-inserted image
Synthiam
#22  
Fixed for next release (later tonight)...

Code:


$buffer="[123 456 789]"
$start=-1
$end=-1

repeat ($ix, 0, length($buffer) - 1, 1)

$ch=GetCharAt($buffer, $ix)

if ($ch = "[")

print("found start")
$start=$ix

ELSEif ($ch = "]")

print("found end")
$end=$ix

endif

ENDrepeat

print($start)
print($end)


Outputs:

Quote:


Start
found start
found end
0
12
Done (00:00:00.0337752)