startmacro


call test_do
call test_while
call test_foreach

endmacro

!******************************************************************************!
procedure test_do

  do count 1 10
    if count EQ 5 then break
  enddo
  assert/text="^reg.main.name: single loop" count EQ 5

  result total 0
  do outer 1 3
    do inner 1 3
      if inner EQ 2 then break
      calc total total 1 +
    enddo
  enddo
  assert/text="^reg.main.name: DO double loop, break inner" &
        inner EQ 2 AND outer EQ 3 AND total EQ 3

  result total 0
  do outer 1 3
    do inner 1 3
      if inner EQ 2 then break 2
      calc total total 1 +
    enddo
  enddo
  assert/text="^reg.main.name: DO double loop, break both" &
       inner EQ 2 AND outer EQ 1 AND total EQ 1
return

!******************************************************************************!
procedure test_while

  result i 0
  while i LT 10
    if i EQ 5 then break
    calc i i 1 +
  endwhile
  assert/text="^reg.main.name: WHILE" i EQ 5
  
return

!******************************************************************************!
procedure test_foreach

  result t:tab {a=1,b=2,c=3,d=4,e=5}
  result i 0
  foreach key INTABLE tab
    if key EQS "D" then break
    calc i i 1 +
  endfor
  assert/text="^reg.main.name: FOREACH" i EQ 3

return
