XV Lidar Bridge icon XV Lidar Bridge — Neato XV LIDAR integration for ARC with live radar, 8-zone obstacle detection, NMS support, calibration, and scan watchdog monitoring Try it →
USA
Asked — Edited
Elseif Is Broken

Elseif Is Broken

@DJ,

The ElseIf is broken:

The code below never stops !


$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.


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


ARC Pro

Upgrade to ARC Pro

With ARC Pro, your robot is not just a machine; it's your creative partner in the journey of technological exploration.

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#17  

Let me take a look and see how this can be... stay tuned

#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

Author Avatar
PRO
USA
#21  

yes i agree with you.

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

OK:


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:


repeatwhile($a<=10)

it get lost forever:

User-inserted image

Author Avatar
PRO
Synthiam
LinkedIn Thingiverse Twitter YouTube GitHub
#22  

Fixed for next release (later tonight)...


$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)