break statement

This is a discussion on break statement within the C++ Programming forums, part of the General Programming Boards category; sorry for asking such a simple question, but i'm not too comfortable using break statements outside of switch. Will the ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    4

    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;
    
    }
    Last edited by Motisa; 10-04-2002 at 02:51 PM.

  2. #2
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    You can also write the program without using a break in loops.

    Mr. c

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    4
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Number to Word (Billions)
    By myphilosofi in forum C Programming
    Replies: 34
    Last Post: 02-04-2009, 02:09 AM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 02:01 AM
  3. Break statement issues, how to return to start of loop?
    By brdiger31 in forum C++ Programming
    Replies: 3
    Last Post: 06-01-2007, 04:29 PM
  4. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  5. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21