How would I write a statement that will loop continuously as long as an array contains a certain value? I need it to continue to loop as long as an array contains a specific character, but stop looping if the array does not contain those said character values.
I kinda have this below, but I'm almost 100% sure it won't work
for(int PieceChecker = 0, PieceChecker < 1){
//Code that needs to be carried out
if (Arrays.asList(board).contains(♖)){
PieceChecker++;
}
}
It is easier to handle cases like these which involve just characters, by using a string than a list. Use an infinite for
loop and break out of it once you find the absence of that character in it. You can use the indexOf
for this purpose.
Here is the code snippet that might help you:
String board_string = new String(board);
for(;;) {
if(board_string.indexOf('♖') == -1) {
System.out.println("Breaking out of loop...");
break;
}
else {
//do something here
}
}