-
break statement
sorry for asking such a simple question, but i'm not too comfortable using break statements outside of switch.
Will the my break statement take me outside of the loop if the condition is true?
Code:
bool PokerHand::is_Royal_flush(const vec& hand){
bool Same_suits = false;
Suit aSuit = hand[0].get_suit();
unsigned int i = 1;
while( i < hand.size() ){
if(hand[i].get_suit() != aSuit){
Same_suits = false;
break;
}
else{
Same_suits = true;
++i;
}
}
return Same_suits;
}
-
You can also write the program without using a break in loops.
Mr. c
-
yes, but i think it is more efficent to break out of the loop once it finds one card that doesn't have the same suit as the other ones because it cannot be a royal flush.