C
C#3y ago
Triufelis

❔ Ace value of 1 or 11

I am writing a blackjack game. I have written a method to calculate the amount of "score" the player has. But the method has two separate foreaches. That is not necessarily how a method should be coded. Is there a way to remove one of the foreaches? so it fits the definition of a method?
9 Replies
Angius
Angius3y ago
uh A method can have 69 foreaches nested inside of 420 wheres It's still a method (also, why virtual..?)
Anton
Anton3y ago
looks ok as is
VIPER
VIPER3y ago
Can u not just use an else Oh nvm Ye that’s fine
Tvde1
Tvde13y ago
you could use an else to make it more performant count the number of aces in the one loop and in the second loop, loop for that count
Triufelis
TriufelisOP3y ago
cause its inside an abstarct class. Im just practising all i learn. Putting it all to use. Well at uni, they teach us that there cant be 2 seperate fors or foreaches as that goes agains the principles of OOP. Nested fors and foreaches are good.
Angius
Angius3y ago
They're full of shit, then
Anton
Anton3y ago
what
Angius
Angius3y ago
But no worries Most schools are
Triufelis
TriufelisOP3y ago
Well the logic is that one method should do only one thing Seems unreasonable But it is what it is 🙂

Did you find this page helpful?