[Gambas-user] WHILE and AND: please explain me....
Leonardo Miliani
leonardo at ...1237...
Wed May 5 01:13:01 CEST 2010
I'm working with this little piece of code, it's the Insertion Sort:
PUBLIC SUB InsertionSort(matrix AS String[])
DIM i, j AS Integer
DIM x AS String
FOR i = 1 TO (matrix.Count - 1)
x = matrix[i]
j = i - 1
WHILE j >= 0 AND matrix[j] > x
matrix[j + 1] = matrix[j]
j -= 1
WEND
matrix[j + 1] = x
NEXT
END
But I get an "Out of bound" error in the WHILE test, because j begins
-1.
Usually (in other languages this is the behavior) the AND test checks
the first condition, and if it is false then it checks the second one.
OK... but shouldn't Gambas bypass the WHILE statement because j is
negative?
--
Leonardo Miliani
www.leonardomiliani.com
Webmaster e co-fondatore di www.gambas-it.org
Il portale di riferimento per i programmatori Gambas italiani
More information about the User
mailing list