I’m trying to understand the follow code below:
/**
* Simple insertion sort.
* @param a an array of Comparable items.
*/
public static void insertionSort( Comparable [ ] a )
{
for( int p = 1; p < a.length; p++ )
{
Comparable tmp = a[ p ];
int j = p;
for( ; j > 0 && tmp.compareTo( a[j-1] ) < 0; j-- )
a[ j ] = a[ j - 1 ];
a[ j ] = tmp;
}
}
But i’m not sure what means for( ; ) so I need your help guys.
Sorry if it’s duplicated but I search here and in Google but nothing so far.
The first part of a for loop is what happens before the looping begins. Usually it’s used for assigning a variable.
The “;” with nothing (apart from the bracket) before it merely says “There’s nothing I want doing before the start of the loop”. No variable needs to be assigned, etc.