for(int j=0;j<numberOfLevels;j++)
{
if(levelsArray[i]<levelsArray[j])
{
int temp1=levelsArray[i];
int temp2=scoresArray[i];
int temp3=starsArray[i];
levelsArray[i]=levelsArray[j];
scoresArray[i]=scoresArray[j];
starsArray[i]=starsArray[j];
All you need to do to convert 'for' to 'while' is take the control variable and declare/initialize it before the loop. Take the Boolean expression and use it for the 'while' statement. All you have left to do is put the counter in the body of the loop.