The School of Hard Knocks is within each of us. Its experience, and millions of hours testing various algorithms to find the most efficient.
Ancient Dragon
Retired & Loving It
30,042 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Depends on how much sleep you need.
You can always stick a finger in a powersocket and hope your brain gets somehow rearranged (improved), but my instinct is telling me that the change of succes will be greater if you just practice , practice and practice ;)
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
a for loop works like this:
for ( init-expression ; cond-expression ; loop-expression )
{
statement
}
Your example only uses the init-expression amd cond-expression. So if 'sort' isn't changed in the statement-block this is an endless loop (you set 'sort' to 1, then loop while it's 1). This is normally written as: while(1) or for(;;)
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
Sure you can. DigitalPackrat sets sort to 0 in the loop, so it won't be endless. I was just trying to give you an insite on for-loops .
I prefer another way to write this loop:
int sorted = 0;
while (!sorted)
{
}
It reads a bit easier.
Nick Evan
Not a Llama
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403