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

# Thread: Proper way to get rid of breaks.

1. ## 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;
}
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");
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. ## Re: Proper way to get rid of breaks.

Why do you want to get rid of them?

3. ## Re: Proper way to get rid of breaks.

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

4. ## Re: Proper way to get rid of breaks.

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.

5. ## Re: Proper way to get rid of breaks.

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

6. ## Re: Proper way to get rid of breaks.

Originally Posted by Massaslayer
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.

Originally Posted by Massaslayer
& yes all works then i'm done
Congratulations!

7. ## 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.