what is the purpose of the for-loop in this program?
i had to make a program to order a couple numbers, and it works, but i'm not sure why the purpose the for-loop has (i know what a for loop is, just not why i need it here)
Lets talk about whats wrong with this program.
First, don't use the sepples sort function, write your own nlog(n) sort function. eg.
void QSort(int *arr, int l, int r)
{
int i = l, j = r;
int holder;
int pt = arr[(l + r) / 2];
while (i <= j) {
while (arr[i] < pt)
i++;
while (arr[j] > pt)
j--;
if (i <= j) {
holder = arr[i];
arr[i] = arr[j];
arr[j] = holder;
i++;
j--;
}
};
if (left < j)
quickSort(arr, l, j);
if (i < right)
quickSort(arr, i, r);
}
Second, don't use the windows library unless you are going to be creating a GUI for windows.
Third, store the loop counter in the register, or even better don't use a loop at all if you are only printing 3 values to the console.
>>6
Yes, it's always better to reinvent fucking everything, instead of using any functions or libraries that the OS already provides. Absolutely never use anything that exists already.
(And if you are skeptical that this is in fact the best way to design a program, consider the fact that this methodology was used to create such wonderful and popular pieces of software such as Google Chrome!)
The main difference between different kinds of loops is when the initial condition is checked.
Name:
Anonymous2010-10-06 18:21
>>14
I always write for (;;) {...} loops, so I get to check at the condition anytime I want, even multiple times, and can select whether it's a while loop or a repeat block with break or continue.
>>16
I always declare all my variables globally, so that if I need to get to the same value from one function to the next, it's always there and I don't waste space on the stack.