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

Which loop is faster?

Name: Anonymous 2012-01-16 8:59


for (I = 0; I < N; I++)
  for (J = 0; J < M; J++)
    update(Xs[I][J]);

or

for (I = 0; I < N; I++)
  for (J = 0; J < M; J++)
    update(Xs[J][I]);

???

Name: Anonymous 2012-01-16 12:18

>>34
Implement it in Java, it should be EASILY DEPLOYABLE AND SCALABLE IN CORPORATE ENVIRONMENTS

Name: Anonymous 2012-01-16 12:19

>>34
size / i will probably result in something bad when i == 0.

Name: Anonymous 2012-01-16 12:19

>>34
Are you tring to imply these two do the same thing?
size/i with i<size
huh?

Name: Anonymous 2012-01-16 12:20

Fuck you, dubs guy.

Name: Anonymous 2012-01-16 12:21

>>44
;_;

J-Jackson, forty-five, g-get... I c-can't do this~

Name: Anonymous 2012-01-16 12:26

>>34
IHBT

size/0 && size%0

Are both undefined.

Name: Anonymous 2012-01-16 12:41

>>37
Are you fucking dense or retarded? for (i = 0; i < X; ++i) and for (i = 0; i < X; i++) result in the same thing, I used the example with int var = ++i and int var = i++ to prove the point that i++ and ++i are two very different things and one of them (depending on the compiler/interpreter/whatever) may yield better performance than the other, unless the compiler figures it out.

Now get some basic reading comprehension and go back to /g/ where you belong.

Name: Anonymous 2012-01-16 12:42

>>37
Seriously, HOW FUCKING HARD IS IT TO READ?

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 12:55

>>48
Perhaps you should write some actual code instead of googling shit. Anyways, here is what I came up with...

public class Main {

    public static void main(String[] args) {
        int i = 0;

        for (i = 0; i < 5; i++) {

        }//end first for

        System.out.println("The value of i is " + i);

        i = 0;

        for (i = 0; i < 5; ++i) {

        }//end second for

        System.out.println("The value of i again is " + i);
    }

}

And the output is..

run:
The value of i is 5
The value of i again is 5
BUILD SUCCESSFUL (total time: 0 seconds)

Name: Anonymous 2012-01-16 12:55

>>34

for (int i = 0; i < size; i++}
    array[size / i][size % i] = value;

The fuck is this?

1) First of all, division by zero in size / 0 and size % 0
2) Then, if size is 10, your indexes will be as follows:

10 0
5 0
3 1
2 2
2 0
1 4
1 3
1 2
1 1


You're not covering all the elements, and you are certainly going out of bounds if size = height * width.

Name: Anonymous 2012-01-16 12:57

>>49
Yes, they produce the same output you mental midget. That's not what is being discussed. Keep up or go back to /g/

Name: Anonymous 2012-01-16 12:59

>>49

i = 0;
for (i = 0; [...]

Why?

Name: Anonymous 2012-01-16 13:02

>>51
That reply was meant for >>37.

Name: Anonymous 2012-01-16 13:02

>>34-36,38-41
You all need to learn some basic maths. You nitpick about size / 0 when that snippet of code isn't even going to cover half of the elements in that array.

Name: Anonymous 2012-01-16 13:03

>>53
Okay then, sorry.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:05

>>50
Again, I think you need to write some code instead of just googling shit. Oh wait, you don't have the mental capacity to code! Anyways, here is what I get when I run the loop in Java...

public class Main {

    public static void main(String[] args) {
        int value = 0;
        int size = 5;

        int[][] array = new int[10][10];
        for (int i = 0; i < size; i++)
            array[size / i][size % i] = value;
       
    }
}

run:
Exception in thread "main" java.lang.ArithmeticException: / by zero
        at Main.main(Main.java:10)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Name: Anonymous 2012-01-16 13:07

>>56
Division by zero isn't the only problem there. (And why are you responding to me, I clearly pointed that out in >>50.

1) First of all, division by zero in size / 0 and size % 0

Name: Anonymous 2012-01-16 13:07

>>56
More to the point, look at the error messsage. Psst... the complaint is about / and not %.

Name: Anonymous 2012-01-16 13:07

>>54
Since it starts at 0
It's gonna crash x segfault at the start, there was no point in even trying to figure out what's gonna happen next.

Name: Anonymous 2012-01-16 13:08

>>56
What are you on about?
Exception in thread "main" java.lang.ArithmeticException: / by zero

That's EXACTLY WHAT I SAID:
>>50
1) First of all, division by zero in size / 0 and size % 0
division by zero

Name: Anonymous 2012-01-16 13:11

>>59
Division by zero is an error easy to make, but also easy to fix (comparable to a syntax error). Not understanding how division and modulo works, however, shows a fundamental lack of understanding.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:11

>>60
Ughhh... I keep forgetting that % isn't the same as % in other programming languages.

Name: Anonymous 2012-01-16 13:12

>>49
They produce the same output in this case.
The pre-increment operator(++i), increments and returns (only one value stored)
The post-increment operator(i++), returns a value of i and holds the incremeneted value for itself(2 values in memory);

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:13

>>61
But according to the JSP, % isn't modulo.

Name: Anonymous 2012-01-16 13:13

>>62
wat

It's the same in most C-like languages.

Name: Anonymous 2012-01-16 13:14

>>64
HOLY SHIT % NOT MODULO OPERATOR,
stop the presses

Name: Anonymous 2012-01-16 13:15

>>64
I'm not following your aspie thought of train at all... Why are you calling me a mental midget and responding to my posts, when you point out the exact same things I just said in my posts.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:15

>>65
No it isn't! Read the Java Standard. It isn't the same.

Name: Anonymous 2012-01-16 13:16

>>63
>The pre-increment operator(++i), increments and returns (only one value stored)
>The post-increment operator(i++), returns a value of i and holds the incremeneted value for itself(2 values in memory);
Unless the compiler notices that there are no assignments and decides to optimize it, thus the two statements are identical for this purpose.

Name: kodak_gallery_programmer !!kCq+A64Losi56ze 2012-01-16 13:17

>>66
It really isn't. And the fact that you think it is reflects the fact that you don't understand how crap languages like Java work.

Name: Anonymous 2012-01-16 13:17

>>68
Java Standard
JSP isn't Java.

Name: Anonymous 2012-01-16 13:18

>>70
JSP == Java
Nope, try again. Go back to the image boards.

Name: Anonymous 2012-01-16 13:18

>>67
I'm confusing you with the moron toilet scrubber.

Name: Anonymous 2012-01-16 13:18

>>73
You don't read before you respond. How surprising...

Name: Anonymous 2012-01-16 13:19

>>72
Go learn what % is you mental midget.

Name: Anonymous 2012-01-16 13:21

>>75
What the fuck is going on in this thread? % is modulo, even in JSP. <% however is not, but then again, that's not valid syntax in any C-like language.

Kodak either confirmed for troll or a complete retard.

Name: Anonymous 2012-01-16 13:22

>>74
For reasons that elude me, my coworkers insist on referring to the Java Language Specification as JSP. Anyways, the language specification clearly states that % isn't modulo.

Name: Anonymous 2012-01-16 13:22

>>76
or both

Name: Anonymous 2012-01-16 13:22

>>76
No it isn't you moron.

Name: Anonymous 2012-01-16 13:23

>>76
No, the Java Language Specification clearly states that % isn't  modulo.

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