Jump to content

While-loop condition not working as it should

Go to solution Solved by Stefan1024,

The while must be above the {} or you need to use the "do while" command.

Hi.

 

I am making a small card game. My cards are stored in File[] whiteCard. 

I have another boolean[] deckWhiteCards that is supposed to check if the card you are trying to deal is in the deck. 

 

This is how I have done this:
 

        int i;        {            i = (int) ((Math.random() * (whiteCards.length-1)) +1);        }        while (deckWhiteCards[i] == true)                    deckWhiteCards[i] = true;

However, players still receive duplicate cards. 

I have been staring at this while-loop for some time now, and I can't see why this shouldn't work.

 

 

Thanks.

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to post
Share on other sites

The while must be above the {} or you need to use the "do while" command.

Mineral oil and 40 kg aluminium heat sinks are a perfect combination: 73 cores and a Titan X, Twenty Thousand Leagues Under the Oil

Link to post
Share on other sites

The while must be above the {} or you need to use the "do while" command.

Of course! Added the do, and now it works. How stupid of me to forget that.

I hardly ever use this type of loops. 

Running Arch with i3-gaps on a Thinkpad X1 Extreme
Data Science Postgrad

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×