B4R Question Do While vs Do Until

canalrun

Well-Known Member
Licensed User
I'm converting a C program to B4R.

In the C program I have:
B4X:
do {
  l >>= 1
} while (mr+l > nn)

above "l >>= 1" is guaranteed to execute at least once.

in B4R if I do:
B4X:
Do Until ((mr + l) <= nn)
  l = Bit.ShiftRight(l, 1)
Loop

Is this the same?
Is the condition tested at the top or end of the loop?
Is "l = Bit.ShiftRight(l, 1)" guaraneed to execute at least once.

Or maybe in B4R if I do:
B4X:
Do While (True)
  l = Bit.ShiftRight(l, 1)
  if ((mr + l) <= nn) then exit
Loop

The documentation and "Beginners Manual" don't explicitly answer this.

Thanks,
Barry.
 

OliverA

Expert
Licensed User
You’ll have to go the do while true route or
B4X:
l = Bit.ShiftRight(l, 1)
Do Until ((mr + l) <= nn)
  l = Bit.ShiftRight(l, 1)
Loop
or a little closer to the original (when it comes to the condition)
B4X:
l = Bit.ShiftRight(l, 1)
Do While (mr+l > nn)
  l = Bit.ShiftRight(l, 1)
Loop
 
Upvote 0
Top