Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

noob c++

Name: Anonymous 2010-10-05 20:41

/g/ doesn't like beginners ;_;

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)

http://pastebin.com/8Aarr5Ni

Name: Anonymous 2010-10-05 20:52

All it does is display everything in the num array.

Name: Anonymous 2010-10-05 21:07

if you dont even know what a for loop does you should learning Python and not C++

Name: Anonymous 2010-10-05 21:21

>>3
Python is every bit as procedural as C++, and most certainly has for loops as a prominent language feature. Maybe >>1 should be learning Haskell.

Name: Anonymous 2010-10-05 21:23

"FOR every item in x, do whatever."

Example: FOR every cow on the farm, milk until there are no more cows.

Name: Anonymous 2010-10-05 21:26

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.

Finally, never use system.

Name: Anonymous 2010-10-05 23:11

>>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!)

Name: Anonymous 2010-10-06 2:11

>>6
hand written sort
faster than the sepples sort

Have you tried benchmarking lately?

Name: Anonymous 2010-10-06 2:50

>>4
Uh, I think the idea is to avoid total clusterfucks like C++ until you at least know what loops are for, not to avoid ever encountering them.

Name: Anonymous 2010-10-06 3:17

>>8
I think I might:
Sepples sort: Ordered 0 to 200000 - 0.20 seconds
Sepples sort: Ordered 200000 to 0 - 0.20 seconds
Handwritten Quicksort: Ordered 0 to 200000 - 0.25 seconds
Handwritten Quicksort: Ordered 200000 to 0 - 0.26 seconds
You win this round...

Name: Anonymous 2010-10-06 10:50

>>9
Uh,
Retard detected.

Name: Anonymous 2010-10-06 10:56

>>11
Mad because I pointed out your error?

Name: Anonymous 2010-10-06 11:02

>>1

Basically, just write shit in C++ until you get why and when you're supposed to use for and while loops.

Name: Anonymous 2010-10-06 14:15

The main difference between different kinds of loops is when the initial condition is checked.

Name: Anonymous 2010-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.

Name: Anonymous 2010-10-06 19:07

>>15
I always use intmax_t because I just never know when I'll want that extra range.

Name: Anonymous 2010-10-06 20:05

>>15
I always use loops made using goto for that refreshing rebelliousness

Name: Anonymous 2010-10-06 20:06

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

Name: Anonymous 2010-10-06 20:51

I always punch myself in the dick whenever I read /prog/

Name: Anonymous 2010-10-06 22:10

>>18
I write everything in the main function because function calls are just too slow.

Name: Anonymous 2010-10-06 23:50

>>18
I always declare all my variables into a global array, so that I don't waste space on the symbol table.

Name: Anonymous 2010-10-07 0:24

I always unroll my loops manually, so that compiler behaviour doesn't affect me.

Name: Anonymous 2010-10-07 0:35

GOTO DISASTER AVERTED

Name: Anonymous 2010-10-07 0:55

I only write code that uses Duff's Device.

Name: Anonymous 2010-10-07 1:04

>>24
$ cat /dev/duffs
cat: /dev/duffs: No such file or directory

Name: Anonymous 2010-10-07 1:22

>>22
Only noobs write loops in the first place, only to have to unroll them later.

Name: Anonymous 2010-12-09 22:49

Don't change these.
Name: Email:
Entire Thread Thread List