| | |
nested for loop problem
![]() |
•
•
Join Date: Sep 2004
Posts: 42
Reputation:
Solved Threads: 0
I'm making a rock paper scissors game, and in this game there is a nested for loop so that the players challenge each other, the outer loop is supposed to loop through all the players starting with player 1, while the inner loop starts at the last player and moves to the outer loop player, this sounds simple enough but for some reason the loop I am trying to use doesn't work. Here is what the loop looks like:
Java Syntax (Toggle Plain Text)
for (j = 0; j < playerNum; j++) { for (k = (playerNum - 1); k > j; k--) { if(j == k) { continue; } players[j].challenge(players[k]); // challenge player[j] with player[k] /* Save current player's results to gameResults total. * Put each player result on a new line. */ gameResults += players[j].getWins() + "\n"; } }
•
•
Join Date: Jan 2006
Posts: 12
Reputation:
Solved Threads: 1
java Syntax (Toggle Plain Text)
for (j = 0; j < playerNum; j++) { for (k = (playerNum - 1); k > j; k--) { // j==k test not needed, k>j players[j].challenge(players[k]); // challenge player[j] with player[k] } /* Save current player's results to gameResults total. * Put each player result on a new line. */ gameResults += players[j].getWins() + "\n"; }
![]() |
Similar Threads
- Alright this loop problem is bugging me (Java)
- I think Loop problem (Java)
- Help w/ for loop. (C++)
- loop problem (C)
- Random Different Number in each loop ?? HLP Me PLZ (c or c++) (C++)
- loop problem (C++)
Other Threads in the Java Forum
- Previous Thread: I need help....again! :(
- Next Thread: cant get the final sum
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





