i think not, the "continue" continues only the for loop. use "break" instead. but otherwise the function does its job.

by the way, for large arrays shuffling is faster and works in O(length), while your algorithm takes O(length^2).