❔ 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?
20 Replies
uh
A method can have 69 foreaches nested inside of 420 wheres
It's still a method
(also, why
virtual
..?)looks ok as is
Can u not just use an else
Oh nvm
Ye that’s fine
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
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.
They're full of shit, then
what
But no worries
Most schools are
Well the logic is that one method should do only one thing
Seems unreasonable
But it is what it is 🙂
you're misinterpreting what they said
I mean, it is doing one thing
most likely
And uses two loops to achieve that
Idk. If the loops are nested it is alright. But if they are seperate ones. Like the ones i sent before. Then it is not alright. Maybe i misinterpreted what the teaches wanted to say. But the fact still remains
It is perfectly fine
Although, I guess, you could merge those loops into one
I hate this 😅
To get back to the question: If you do
then you'll get one loop that does what both of these loops do
no, they gather the counts in the first loop, look closer
You could replace the first foreach with this.
Though, it's just doing the same thing, just a little neater imo.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.