Hello. My question is how do i break out of the for loop after the entire deck has been used? Here is my code.


import javax.swing.*;import java.util.*;import java.util.Arrays;import java.util.Random; public class GameOfWar{public static void main(String &#91;&#93; args){ String name=JOptionPane.showInputDialog(null, "Enter player 1's name.");String name2=JOptionPane.showInputDialog(null, "Enter player 2's name.");//deck Integer &#91;&#93; deck1 = new Integer &#91;52&#93;; for(int i = 0; i < deck1.length; i ++){ deck1&#91;i&#93; = i+1; }//procedures Collections.shuffle(Arrays.asList(deck1)); String player1card = "";String player2card = "";int value1 = 0;int value2 = 0; int player2count = 0;int player1count = 0; boolean war = false;boolean again = true; int win = 0;int lose = 0;int againAns = 0; do{ for(int j = 0; j < deck1.length; j++){ //Draws switch(deck1&#91;j&#93;) { case 1: player1card="2 of hearts"; player2card="2 of hearts"; value1 = 1; break; case 2: player1card="3 of hearts"; player2card="3 of hearts"; value1 = 2; break; case 3: player1card="4 of hearts"; player2card="4 of hearts"; value1 = 3; break; case 4: player1card="5 of hearts"; player2card="5 of hearts"; value1 = 4; break; case 5: player1card="6 of hearts"; player2card="6 of hearts"; value1 = 5; break; case 6: player1card="7 of hearts"; player2card="7 of hearts"; value1 = 6; break; case 7: player1card="8 of hearts"; player2card="8 of hearts"; value1 = 7; break; case 8: player1card="9 of hearts"; player2card="9 of hearts"; value1 = 8; break; case 9: player1card="10 of hearts"; player2card="10 of hearts"; value1 = 9; break; case 10: player1card="Jack of hearts"; player2card="Jack of hearts"; value1 = 10; break; case 11: player1card="Queen of hearts"; player2card="Queen of hearts"; value1 = 11; break; case 12: player1card="King of hearts"; player2card="King of hearts"; value1 = 12; break; case 13: player1card="Ace of hearts"; player2card="Ace of hearts"; value1 = 13; break; case 14: player1card="2 of spades"; player2card="2 of spades"; value1 = 1; break; case 15: player1card="3 of spades"; player2card="3 of spades"; value1 = 2; break; case 16: player1card="4 of spades"; player2card="4 of spades"; value1 = 3; break; case 17: player1card="5 of spades"; player2card="5 of spades"; value1 = 4; break; case 18: player1card="6 of spades"; player2card="6 of spades"; value1 = 5; break; case 19: player1card="7 of spades"; player2card="7 of spades"; value1 = 6; break; case 20: player1card="8 of spades"; player2card="8 of spades"; value1 = 7; break; case 21: player1card="9 of spades"; player2card="9 of spades"; value1 = 8; break; case 22: player1card="10 of spades"; player2card="10 of spades"; value1 = 9; break; case 23: player1card="Jack of spades"; player2card="Jack of spades"; value1 = 10; break; case 24: player1card="Queen of spades"; player2card="Queen of spades"; value1 = 11; break; case 25: player1card="King of spades"; player2card="King of spades"; value1 = 12; break; case 26: player1card="Ace of spades"; player2card="Ace of spades"; value1 = 13; break; case 27: player1card="2 of diamonds"; player2card="2 of diamonds"; value1 = 1; break; case 28: player1card="3 of diamonds"; player2card="3 of diamonds"; value1 = 2; break; case 29: player1card="4 of diamonds"; player2card="4 of diamonds"; value1 = 3; break; case 30: player1card="5 of diamonds"; player2card="5 of diamonds"; value1 = 4; break; case 31: player1card="6 of diamonds"; player2card="6 of diamonds"; value1 = 5; break; case 32: player1card="7 of diamonds"; player2card="7 of diamonds"; value1 = 6; break; case 33: player1card="8 of diamonds"; player2card="8 of diamonds"; value1 = 7; break; case 34: player1card="9 of diamonds"; player2card="9 of diamonds"; value1 = 8; break; case 35: player1card="10 of diamonds"; player2card="10 of diamonds"; value1 = 9; break; case 36: player1card="Jack of diamonds"; player2card="Jack of diamonds"; value1 = 10; break; case 37: player1card="Queen of diamonds"; player2card="Queen of diamonds"; value1 = 11; break; case 38: player1card="King of diamonds"; player2card="King of diamonds"; value1 = 12; break; case 39: player1card="Ace of diamonds"; player2card="Ace of diamonds"; value1 = 13; break; case 40: player1card="2 of clubs"; player2card="2 of clubs"; value1 = 1; break; case 41: player1card="3 of clubs"; player2card="3 of clubs"; value1 = 2; break; case 42: player1card="4 of clubs"; player2card="4 of clubs"; value1 = 3; break; case 43: player1card="5 of clubs"; player2card="5 of clubs"; value1 = 4; break; case 44: player1card="6 of clubs"; player2card="6 of clubs"; value1 = 5; break; case 45: player1card="7 of clubs"; player2card="7 of clubs"; value1 = 6; break; case 46: player1card="8 of clubs"; player2card="8 of clubs"; value1 = 7; break; case 47: player1card="9 of clubs"; player2card="9 of clubs"; value1 = 8; break; case 48: player1card="10 of clubs"; player2card="10 of clubs"; value1 = 9; break; case 49: player1card="Jack of clubs"; player2card="Jack of clubs"; value1 = 10; break; case 50: player1card="Queen of clubs"; player2card="Queen of clubs"; value1 = 11; break; case 51: player1card="King of clubs"; player2card="King of clubs"; value1 = 12; break; case 52: player1card="Ace of clubs"; player2card="Ace of clubs"; value1 = 13; break; } if(j%2==0) { JOptionPane.showMessageDialog(null, name +" drew a " + player1card); player1count = value1; } else { JOptionPane.showMessageDialog(null, name2 + " drew a " + player2card); player2count = value1; }//================================================== ============================================ if(j%2==1) { if(player1count > player2count) { if(war==true) { win+=4; war = false; } win +=2; JOptionPane.showMessageDialog(null, name + " wins"); JOptionPane.showMessageDialog(null,name + "'s score: " + win +"&#092;n" + name2 +" score: " +lose ); } if(player1count < player2count) { if(war == true) { lose+=4; war = false; } lose+=2; JOptionPane.showMessageDialog(null, name2 + " wins!"); JOptionPane.showMessageDialog(null,name2 + "'s score: " + win + "&#092;n" + name +" score: " + lose ); } if(player1count == player2count) { war = true; JOptionPane.showMessageDialog(null, "WAR"); } } } } while(again = true);//win if(player1count > player2count) { JOptionPane.showMessageDialog(null, name + "wins!"); } else { JOptionPane.showMessageDialog(null, name + " loses. " + "&#092;n" + name +"'s score: " + player1count + "&#092;n" +name2 + "'s score: " + player2count); } againAns = JOptionPane.showConfirmDialog(null, "Would you like to play agian?"); if(againAns == JOptionPane.YES_OPTION) { again = true; win=0; lose=0; } else if(againAns == JOptionPane.NO_OPTION) { again = false; JOptionPane.showMessageDialog(null, "Thank you and goodbye"); } } }

Sorry that the code is disorganized. I've sent this from my phone.

More...