Skip to content

Latest commit

 

History

History
121 lines (105 loc) · 6.96 KB

File metadata and controls

121 lines (105 loc) · 6.96 KB

Documentation

for

for [variable assignment] to [expression] step [expression]
  [statement]
next

The for is a cycle that supports a single local variable identified by # that can be set with an initial value and a limit value that is specified after to:

for #i = 0 to 5
  print #i
next

// Prints 0, 1, 2, 3, 4

In the example above #i is locally declared with a value of 0 and it will be incremented by 1 at each cycle. The for iterates the local variable up or down to the desired limit in both directions:

for #i = 5 to 0
  print #i
next

// Prints 5, 4, 3, 2, 1

Each time next is encountered the variable is incremented or decremented by 1 and the cycle restarts if the limit defined after the to is not reached. Consider that for, unlike for defined by other programming languages, evaluates and computes the limit the first time the for statement is encountered. For this reason the for is a quick iterator, if you need to conditionally exit from a loop use while instead.

step

Optionally the for the increment or decrement value can be configured after step:

for #i = 0 to 10 step 2
  print #i
next

// Prints 0, 2, 4, 6, 8

break

The BIPLAN for supports break as other programming languages do:

for #i = 0 to 5
  if #i == 2 break end
  print #i
next
print "Finished"

// Prints 0, 1, Finished

When break is encountered within a for, the iteration is interrupted and all following statements part of the for are ignored.

continue

The BIPLAN for supports continue as other programming languages do:

for #i = 0 to 5
  if #i == 2 continue end
  print #i
next
print "Finished"

// Prints 0, 1, 3, 4, Finished

When continue is encountered within a for, all following statements part of the for are ignored and the next iteration is initiated.


while

while [condition]
  [statement]
next

The while statement, if the condition is truthy, forces the cyclical execution of the following statements until next is encountered.

while io read 12 == HIGH
  print "The pin is HIGH"
next

// Prints The pin is HIGH until pin 12 is HIGH

break

The BIPLAN while supports break as other programming languages do:

while true
  if io read 12 == HIGH
    break
  end
next
print "Button pressed!"

// Prints Button pressed when pin 12 is HIGH

When break is encountered within a for, the iteration is interrupted and all following statements part of the for are ignored.

continue

The BIPLAN while supports continue as other programming languages do:

@treshold = 512
while true
  if adc read A0 > @treshold
    continue
  else
    print "Alert"
  end
next

// Prints Alert if the reading is less than 512

When continue is encountered within a for, all following statements part of the for are ignored and the next iteration is initiated.