LibreOffice: Loop in Basic


In the case we want edit cell from top to down in LibreOffice Calc, the loop function is useful.

Environment

  • LibreOffice 5.2.0.4

Sample

When the number of loop iteration is fixed

You can fix the max and min value and use For for loop.

The sample code below changes cell’s background color in LibreOffice Calc.

Adding Step 2 at the last of For line, the value rowIndex increases by 2. With this function, you can make table zebra for example.

If you want to exit the loop while iteration is going, write Exit For. It’s the same as Visual Basic.

Continue iteration only when the condition is meeted

You can use many style for loop in LibreOffice Basic, then I recommend simple one. It is like while (condition) { ... } style in many languages.

If you want to exit the loop while the iteration is going, write Exit Do.