Proper way to get rid of breaks.

• December 19th, 2011, 10:58 AM
Massaslayer
Proper way to get rid of breaks.
Hello all!

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

Code :

``` 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:

Code :

``` 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!
• December 19th, 2011, 11:09 AM
KevinWorkman
Re: Proper way to get rid of breaks.
Why do you want to get rid of them?
• December 19th, 2011, 11:17 AM
Massaslayer
Re: Proper way to get rid of breaks.
Quote:

Originally Posted by KevinWorkman
Why do you want to get rid of them?

It's not clean programming?
• December 19th, 2011, 11:24 AM
KevinWorkman
Re: Proper way to get rid of breaks.
Quote:

Originally Posted by Massaslayer
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.
• December 19th, 2011, 11:37 AM
Massaslayer
Re: Proper way to get rid of breaks.
Quote:

Originally Posted by KevinWorkman
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 :D & yes all works :) then i'm done :D
• December 19th, 2011, 11:41 AM
KevinWorkman
Re: Proper way to get rid of breaks.
Quote:

Originally Posted by Massaslayer
The if states are so difficuly because it are x & y values of game board :D

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
& yes all works :) then i'm done :D

Congratulations!
• December 23rd, 2011, 06:53 PM
imsuperman05
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.