# Loop probrem

• 06-17-2009, 12:16 PM
Manfizy
Loop probrem
I am trying to sort a table and i have used several loops for the sorting. Now my program doesnt terminate.
Could it be something to do with the loop and if so where am i making a mistake coz i just cant figure it out at the moment.
Also is there a better way to sort the table?
below is my code

Code:

public void sortTable(){
int rCount = InputTable.getRowCount();

for ( int i = 0;i<rCount;i++){
double delta =0;
String time =(String) InputTable.getValueAt(i, 0);
double time1 = Double.parseDouble(time);

String power =(String) InputTable.getValueAt(i, 1);

double t = (time1*60)/5;
while (i < t){

ResultTable.setValueAt(delta, i,0);
ResultTable.setValueAt(power, i, 1);

}
delta = delta +5;
}
}

• 06-17-2009, 06:41 PM
emceenugget
Code:

while (i < t){

ResultTable.setValueAt(delta, i,0);
ResultTable.setValueAt(power, i, 1);

}

i and t need to change for this to stop looping
• 06-19-2009, 12:45 PM
Eranga
That means the while loop never end, never evaluate to false. That's what emceenugget mentioned.
• 06-24-2009, 04:48 AM
Webuser
Quote:

while (i < t){
i++; //to make the loop finished )))
ResultTable.setValueAt(delta, i,0);
ResultTable.setValueAt(power, i, 1);
Think it...
}
• 06-25-2009, 04:50 AM
Eranga
It's all depends on the logic you in the application. :)
• 06-25-2009, 06:03 AM
rdtindsm
Without sitting down and actually working it out on paper, I can't tell what you are doing, although I am guessing that you actually mean that you are transposing the table or reordering in someway.

Any kind of sorting algorithm has to have comparisons. Your routine has absolutely none, as of yet. Is the routine part of a larger sorting routine, such as quicksort?

Webuser is right. You didn't increment i. But computers are very good at boring tasks.