I have a little routine used to sort the elements of an array using

*Insertion Sort*.

It looks like :

**Code:**

func Sort (myArray[] as reference to integer)

dim i, j, newValue as integer

for i = 1 to (len(myArray) - 1)

newValue = myArray[i]

j = i

while (j > 0 AND myArray[j - 1] > newValue) do

myArray[j] = myArray[j - 1]

j = j - 1

loop

myArray[j] = newValue

next

endfunc

Unfortunately, it regularly crashes at the beginning of

*while* loop.

The reason is, after first loop,

*j* has the value zero, which is OK.

The loop should be entered if (j > 0) AND previous element in array is bigger than current element.

Since j is equal to zero, the first term of the boolean expression is false, thus the entire boolean expression is false.

In other languages (Java, C, etc.) the second term is not evaluated since it doesn't make sense.

Qlarity throws an exception trying to access a non-existing array element.

How can such a situation be solved in Qlarity ?

Are there some (undocumented ?) options to tell Qlarity, not to evaluate the entire expression if the first term is already false ?

I could of course use a different sorting algorithm but I ask myself how to deal with such a situation.

Regards,

Tony