USA
Asked — Edited

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

ARC Pro will give you immediate updates and new features needed to unleash your robot's potential!

Author Avatar
PRO
USA
#9  

@Richard R: Last version ?

#12  

@ptp You are right! I forgot to check the boundary conditions..

$A=3 breaks it with the latest ARC

I get the same "Start" message that you do

User-inserted image

Thanks, Frank

Author Avatar
PRO
Synthiam
#13  

$a=11
print("Start")
if ($a=1)
  print("one")
ELSEif ($a=3)
  print("three")
ELSEif ($a=5)
  print("five")
ELSE
  print("another number")
endif
print("End")

Outputs (correct):

Quote:

Start Start another number End Done (00:00:00.0156256)



$a=3
print("Start")
if ($a=1)
  print("one")
ELSEif ($a=3)
  print("three")
ELSEif ($a=5)
  print("five")
ELSE
  print("another number")
endif
print("End")

Outputs (correct):

Quote:

Start Start three End Done (00:00:00.0155859)



$a=5
print("Start")
if ($a=1)
  print("one")
ELSEif ($a=3)
  print("three")
ELSEif ($a=5)
  print("five")
ELSE
  print("another number")
endif
print("End")

Outputs (correct):

Quote:

Start Start five End Done (00:00:00)

Author Avatar
PRO
USA
#14  

@DJ,

It's fixed in your version ? Current version does not work.

Author Avatar
PRO
Synthiam
#15  

I'm using the same version as you.

Your examples are all incorrect - surprised none of you caught any of the incorrectness:D

If you copy and paste my code into your copy of ARC, you will receive the same output. Copy and paste, do not type it because there's lots of mistakes being made in this thread example code. Such as the $a=11 lol

Author Avatar
PRO
USA
#16  

@DJ:

What is the mistake in the code below ?


$a=11
print("***Start")
if ($a=1)
  print("one")
elseif ($a=3)
  print("three")
elseif ($a=5)
  print("five")
endif
print("***End")

the code above produces this:

User-inserted image