• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Just wrote a method which makes my computer's processor go MENTAL. Can anyone tell me why?

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok then i had an idea today that i would try and make a card game. Before I start programing the game properly i started experimenting with things. First i got it into my head that i would represent each card in the deck by using two arrays - one for suit and one for the card number.

Then i kind of just started jamming and learning. Here i was trying to make a way so that once the card had been dealt it wouldn't be dealt again. Anyway i'll post the code first before i continue.





There is one other class that has the main method, that starts another method that invokes the dealRandomCard method.

Please just think of this as a rough draft, more like a doodle. Or an experiment to see what is possible using array lists and arrays.

The problem is that when i compile and run the program (either in eclispe or using command promt, the program runs fine, but then one of my processors (i have a quadcore) maxes out to 100%, and then it stays there until i either close eclispse or exit the command prompt.

What an earth is going on? Why is it doing this?

Sorry if the code seems a bit random. Maybe i should add some comments to say what is doing what. Or maybe it will be obvious to a none beginner i don't know.

 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think i've just worked it out.

it's cause the for loop NEVER ends!


hope someone hasn't gone to the trouble of writing a big long reply!
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!
 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Greg Charles wrote:Yep, that's it. The old infinite loop. Your problem was decrementing the loop index inside the loop. It's generally a bad idea to play around with the loop index like that, and now you know why!



haha i can't believe i did that!

If anyone is wondering what the heck i was thinking of. I was thinking that i wanted the for loop to go until i had printed out 52 cards, and if a certain card generated by a random number had already been generated i wanted the for loop to go again like nothing had happend. Oh well i think i would be better off using a while loop and just incrementing a variable everytime a card is printed out.

 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic