Community Question

@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 ?

ptp
Commented May 2017
@Alan,

Quote:


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



Not in this tutorial:
https://www.ez-robot.com/Tutorials/UserTutorials/134/1

thetechguru
Commented May 2017
@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
ptp
Commented May 2017
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

DJ Sures
Commented May 2017
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)

DJ Sures
Commented May 2017
Question
Avatarby ptp
Published Sunday, May 14, 2017