Relating to my previous post, I have a function that will order the list of tasks in descending or ascending order by priority. So I merged ascending and descending functions into one bidirectional one, but I'm having a bit of trouble. The for loop works perfectly descending. When ascending, it stops at 3. I'm assuming it has to do with the != operator being wonky when going in that direction?
Code:
int start;
int goal;
if(sort == SORT_ASCENDING)
{
start = 0;
goal = 5;
}
else if(sort == SORT_DESCENDING)
{
start = 5;
goal = 0;
}
for(int priority = start; priority != goal; )
{
// ...
if(sort == SORT_ASCENDING)
{
priority++;
}
else if(sort == SORT_DESCENDING)
{
priority--;
}
}