For loops and array
-
WTF! :omg: What else can I say? :doh: I expect from your statement that the amount of code, over all, could be cut in half. I wonder what other coding gaffs where made.
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
Same beauty but with the strings :D
for (int c = 0; c < b.Length; c++) { if (b[c].Equals("1")) d[1] = d[1] + 1; else if (b[c].Equals("2")) d[2] = d[2] + 1; else if (b[c].Equals("3")) d[3] = d[3] + 1; else if (b[c].Equals("4")) d[4] = d[4] + 1; else if (b[c].Equals("5")) d[5] = d[5] + 1; else if (b[c].Equals("6")) d[6] = d[6] + 1; else if (b[c].Equals("7")) d[7] = d[7] + 1; else if (b[c].Equals("8")) d[8] = d[8] + 1; else if (b[c].Equals("9")) d[9] = d[9] + 1; else if (b[c].Equals("10")) d[10] = d[10] + 1; else if (b[c].Equals("12")) d[12] = d[12] + 1; else if (b[c].Equals("13")) d[13] = d[13] + 1; else if (b[c].Equals("14")) d[14] = d[14] + 1; }
and the "d" is:int[] d = new int[15];
As you can see he use indices from 1 to 14 so he hat to set size of array to 15 instead of 14.Mostly, when you see programmers, they aren't doing anything.
-
Same beauty but with the strings :D
for (int c = 0; c < b.Length; c++) { if (b[c].Equals("1")) d[1] = d[1] + 1; else if (b[c].Equals("2")) d[2] = d[2] + 1; else if (b[c].Equals("3")) d[3] = d[3] + 1; else if (b[c].Equals("4")) d[4] = d[4] + 1; else if (b[c].Equals("5")) d[5] = d[5] + 1; else if (b[c].Equals("6")) d[6] = d[6] + 1; else if (b[c].Equals("7")) d[7] = d[7] + 1; else if (b[c].Equals("8")) d[8] = d[8] + 1; else if (b[c].Equals("9")) d[9] = d[9] + 1; else if (b[c].Equals("10")) d[10] = d[10] + 1; else if (b[c].Equals("12")) d[12] = d[12] + 1; else if (b[c].Equals("13")) d[13] = d[13] + 1; else if (b[c].Equals("14")) d[14] = d[14] + 1; }
and the "d" is:int[] d = new int[15];
As you can see he use indices from 1 to 14 so he hat to set size of array to 15 instead of 14.Mostly, when you see programmers, they aren't doing anything.
Man! If I had the code and the time (which I do not) I would revamp code all over the place. Unrolling loops is an old optimization trick, but you need to know when to do it and when not to. I am not even sure unrolling is even needed today, because the machines today are so fast they make my first computer look like it was standing still. The
new
I understand, I never do it, but people sometimes do it to make it easier to match values with indexes.INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra
-
Same beauty but with the strings :D
for (int c = 0; c < b.Length; c++) { if (b[c].Equals("1")) d[1] = d[1] + 1; else if (b[c].Equals("2")) d[2] = d[2] + 1; else if (b[c].Equals("3")) d[3] = d[3] + 1; else if (b[c].Equals("4")) d[4] = d[4] + 1; else if (b[c].Equals("5")) d[5] = d[5] + 1; else if (b[c].Equals("6")) d[6] = d[6] + 1; else if (b[c].Equals("7")) d[7] = d[7] + 1; else if (b[c].Equals("8")) d[8] = d[8] + 1; else if (b[c].Equals("9")) d[9] = d[9] + 1; else if (b[c].Equals("10")) d[10] = d[10] + 1; else if (b[c].Equals("12")) d[12] = d[12] + 1; else if (b[c].Equals("13")) d[13] = d[13] + 1; else if (b[c].Equals("14")) d[14] = d[14] + 1; }
and the "d" is:int[] d = new int[15];
As you can see he use indices from 1 to 14 so he hat to set size of array to 15 instead of 14.Mostly, when you see programmers, they aren't doing anything.
-
Oh man, I didn't even notice the absence of 11!
-
Oh man, I didn't even notice the absence of 11!
Cards 1 and 11 are the same, so 11 is skipped, at least something is right ;)
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
-
Cards 1 and 11 are the same, so 11 is skipped, at least something is right ;)
Mostly, when you see programmers, they aren't doing anything. One of the attractive things about programmers is that you cannot tell whether or not they are working simply by looking at them. Very often they're sitting there seemingly drinking coffee and gossiping, or just staring into space. What the programmer is trying to do is get a handle on all the individual and unrelated ideas that are scampering around in his head. (Charles M Strauss)
So the underlying design is flawed as well?
-
So the underlying design is flawed as well?
Could be depending on the rules of the game. Normally ace is the highest and lowest card, if for some reason an ace could be a 1, or between 10 and jack the implementation would sorta make sense.
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
-
Could be depending on the rules of the game. Normally ace is the highest and lowest card, if for some reason an ace could be a 1, or between 10 and jack the implementation would sorta make sense.
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
dan neely wrote:
would sorta make sense.
...but not much, there's probably a cleaner way.
-
dan neely wrote:
would sorta make sense.
...but not much, there's probably a cleaner way.
PIEBALDconsult wrote:
dan neely wrote: would sorta make sense. ...but not much, there's probably a cleaner way.
the sorta was representing that fact. I didn't immediately see a better way, but assumed a less ugly construct still should exist.
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
-
Oh, my eyes, my eyes! Why 14? What's in e[0]? Is that d[14] a typo?
PIEBALDconsult wrote:
What's in e[0]?
e[0]? Whats e[0]? Indices are starting from one, ever since VB existed! If you are really oldscool, you may even substitute VB with Fortran...
Failure is not an option - it's built right in.
-
for (int c = 0; c < _myHand.CardCount; c++) { if (_myHand.Cards[c].Equals(1)) e[1] = e[1] + 1; else if (_myHand.Cards[c].Equals(2)) e[2] = e[2] + 1; else if (_myHand.Cards[c].Equals(3)) e[3] = e[3] + 1; else if (_myHand.Cards[c].Equals(4)) e[4] = e[4] + 1; else if (_myHand.Cards[c].Equals(5)) e[5] = e[5] + 1; else if (_myHand.Cards[c].Equals(6)) e[6] = e[6] + 1; else if (_myHand.Cards[c].Equals(7)) e[7] = e[7] + 1; else if (_myHand.Cards[c].Equals(8)) e[8] = e[8] + 1; else if (_myHand.Cards[c].Equals(9)) e[9] = e[9] + 1; else if (_myHand.Cards[c].Equals(10)) e[10] = e[10] + 1; else if (_myHand.Cards[c].Equals(12)) e[12] = e[12] + 1
LMFAO...that's funny. Thanks for the laugh. I'm such a geek..laughing about code.:cool:
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
for (int c = 0; c < _myHand.CardCount; c++) { if (_myHand.Cards[c].Equals(1)) e[1] = e[1] + 1; else if (_myHand.Cards[c].Equals(2)) e[2] = e[2] + 1; else if (_myHand.Cards[c].Equals(3)) e[3] = e[3] + 1; else if (_myHand.Cards[c].Equals(4)) e[4] = e[4] + 1; else if (_myHand.Cards[c].Equals(5)) e[5] = e[5] + 1; else if (_myHand.Cards[c].Equals(6)) e[6] = e[6] + 1; else if (_myHand.Cards[c].Equals(7)) e[7] = e[7] + 1; else if (_myHand.Cards[c].Equals(8)) e[8] = e[8] + 1; else if (_myHand.Cards[c].Equals(9)) e[9] = e[9] + 1; else if (_myHand.Cards[c].Equals(10)) e[10] = e[10] + 1; else if (_myHand.Cards[c].Equals(12)) e[12] = e[12] + 1
whats so difficult about:
for (int c = 0; c < _myHand.CardCount; c++) { e[_myHand.Cards[c]]++; }
This might not work, depending on how the value of the cards are stored, though, in which case just cast to int--- The sum of the intelligence of the world is constant. The total number of people is always increasing.
-
for (int c = 0; c < _myHand.CardCount; c++) { if (_myHand.Cards[c].Equals(1)) e[1] = e[1] + 1; else if (_myHand.Cards[c].Equals(2)) e[2] = e[2] + 1; else if (_myHand.Cards[c].Equals(3)) e[3] = e[3] + 1; else if (_myHand.Cards[c].Equals(4)) e[4] = e[4] + 1; else if (_myHand.Cards[c].Equals(5)) e[5] = e[5] + 1; else if (_myHand.Cards[c].Equals(6)) e[6] = e[6] + 1; else if (_myHand.Cards[c].Equals(7)) e[7] = e[7] + 1; else if (_myHand.Cards[c].Equals(8)) e[8] = e[8] + 1; else if (_myHand.Cards[c].Equals(9)) e[9] = e[9] + 1; else if (_myHand.Cards[c].Equals(10)) e[10] = e[10] + 1; else if (_myHand.Cards[c].Equals(12)) e[12] = e[12] + 1
Oh My God, Please visit this Great Horror
Regards, Sylvester G sylvester_g_m@yahoo.com