1. ## 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

Java 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;
}
}```

2. Senior Member
Join Date
Sep 2008
Posts
564
Rep Power
9
Java 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

3. That means the while loop never end, never evaluate to false. That's what emceenugget mentioned.

4. Senior Member
Join Date
Dec 2008
Posts
526
Rep Power
0
while (i < t){
i++; //to make the loop finished )))
ResultTable.setValueAt(delta, i,0);
ResultTable.setValueAt(power, i, 1);
Think it...
}

5. Member
Join Date
Feb 2009
Posts
92
Rep Power
0
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•