Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Proper way to get rid of breaks.

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Proper way to get rid of breaks.

    Hello all!


    I got the following cod And I absolutley forgot how to get rid of breakse:

    		for (int xTemp = 0; xTemp < board.length; xTemp++) {
    					if (board[xTemp][0] == curpos[0][0] && board[xTemp][1] == (curpos[0][1] + 66) || nopos[xTemp][0] == curpos[0][0] && nopos[xTemp][1] == (curpos[0][1] + 66)) {
    						curpos[0][1] = curpos[0][1] + 66;
    						repaint();
    						break;
    					}
    				}

    More of crappy code with breaks:

    	for (xTemp = 0; xTemp < board.length; xTemp++) {
    				// Rechts
    				if ((isBoardPos(board[xTemp][0] + 66, board[xTemp][1]) == true)
    						&& (isEmptyPos(board[xTemp][0] + 66 * 2,
    								board[xTemp][1]) == true)) {
    					LOG("Is not lost");
    					rechts = true;
    					break;
    				}
    				// Links
    				else if ((isBoardPos(board[xTemp][0] - 66, board[xTemp][1]) == true)
    						&& (isEmptyPos(board[xTemp][0] - 66 * 2,
    								board[xTemp][1]) == true)) {
    					LOG("Is not lost");
    					links = true;
    					break;
    				}
    				// Boven
    				else if ((isBoardPos(board[xTemp][0], board[xTemp][1] + 66) == true)
    						&& (isEmptyPos(board[xTemp][0],
    								board[xTemp][1] + 66 * 2) == true)) {
    					LOG("Is not lost");
    					boven = true;
    					break;
    				}
    				// Onder
    				else if ((isBoardPos(board[xTemp][0], board[xTemp][1] - 66) == true)
    						&& (isEmptyPos(board[xTemp][0],
    								board[xTemp][1] - 66 * 2) == true)) {
    					LOG("Is not lost");
    					onder = true;
    					break;
    				}
    			}


    Thanks a lot for some help

    Greetz!


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Proper way to get rid of breaks.

    Why do you want to get rid of them?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Proper way to get rid of breaks.

    Quote Originally Posted by KevinWorkman View Post
    Why do you want to get rid of them?
    It's not clean programming?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Proper way to get rid of breaks.

    Quote Originally Posted by Massaslayer View Post
    It's not clean programming?
    Why not? Seems fine to me. I'd be more worried about those complicated if statements if I were you.

    Actually, if I were you, I wouldn't worry about any of it. Does it work? Do you understand why and how it works? Then don't worry about it too much.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    10
    My Mood
    Angelic
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Proper way to get rid of breaks.

    Quote Originally Posted by KevinWorkman View Post
    Why not? Seems fine to me. I'd be more worried about those complicated if statements if I were you.

    Actually, if I were you, I wouldn't worry about any of it. Does it work? Do you understand why and how it works? Then don't worry about it too much.
    The if states are so difficuly because it are x & y values of game board & yes all works then i'm done

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Proper way to get rid of breaks.

    Quote Originally Posted by Massaslayer View Post
    The if states are so difficuly because it are x & y values of game board
    You might consider putting them in methods or something. It's pretty hard to tell what they're doing just by looking at them. But really, I wouldn't worry too much about that kind of thing at this stage in the game.

    Quote Originally Posted by Massaslayer View Post
    & yes all works then i'm done
    Congratulations!
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Member
    Join Date
    Dec 2011
    Posts
    34
    My Mood
    Cheerful
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Proper way to get rid of breaks.

    Breaks just stops the loop statement. If you don't have the break there, then it'll execute those methods one at a time accordingly to the board's length. You could just add a break after all the if-else statements.

Similar Threads

  1. Need proper Java Lingo
    By Deceptiron in forum Java Theory & Questions
    Replies: 4
    Last Post: November 22nd, 2010, 09:39 PM
  2. How to insert a proper child in the XML Doc
    By Sarakh in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 31st, 2010, 12:36 PM
  3. making a sentence proper
    By dvsumosize in forum Algorithms & Recursion
    Replies: 5
    Last Post: February 3rd, 2010, 11:01 AM
  4. "java -version" doesn't display proper value.
    By goldest in forum Java Theory & Questions
    Replies: 6
    Last Post: November 1st, 2009, 03:48 PM
  5. Replies: 1
    Last Post: February 28th, 2009, 10:05 PM