How can I shrink down all of these if statements?

refactoring if statements
how to avoid nested if statements in java
how to avoid if statements
if else alternative java
refactoring if statements c#
java 8 if else alternative
java 8 multiple if conditions
how to avoid nested if statements in python

This part of the code is from a school assignment. I got it to work, but I feel like I can simplify it or at least make it look cleaner. However, I have not yet been able to do so. Any suggestions? (It is from a tic tac toe game)

if (board[0][0] == board[0][1] && board[0][1] == board[0][2] && board[0][0] != '-') {
    winner = board[0][0];
} else if (board[1][0] == board[1][1] && board[1][1] == board[1][2] && board[1][0] != '-') {
    winner = board[1][0];
} else if (board[2][0] == board[2][1] && board[2][1] == board[2][2] && board[2][0] != '-') {
    winner = board[2][0];
} else if (board[0][0] == board[1][0] && board[1][0] == board[2][0] && board[0][0] != '-') {
    winner = board[0][0];
} else if (board[0][1] == board[1][1] && board[1][1] == board[2][1] && board[0][1] != '-') {
    winner = board[0][1];
} else if (board[0][2] == board[1][2] && board[1][2] == board[2][2] && board[0][2] != '-') {
    winner = board[0][2];
} else if (board[2][0] == board[1][1] && board[1][1] == board[0][2] && board[2][0] != '-') {
    winner = board[2][0];
} else if (board[0][0] == board[1][1] && board[1][1] == board[2][2] && board[0][0] != '-') {
    winner = board[0][0];


 if(check(board[0][0],board[0][1],board[0][2]) &&  board[0][2]!='-')

private boolean check(a,b,c){
    return a==b && b==c;

also you can see a better solution here

Explorations in Computing: An Introduction to Computer Science, Return the location ofk if it is found, otherwise nil. a[mid] # succeed if k is at the mid 8: if k < a[mid] 9: upper = mid # next search: lower region 10: else looking for is not in the list the region will shrink all the way down to a sublist of size zero. Thanks for contributing an answer to Software Engineering Stack Exchange! Please be sure to answer the question. Provide details and share your research! But avoid … Asking for help, clarification, or responding to other answers. Making statements based on opinion; back them up with references or personal experience.

Here is another way of doing it:

int[][] checks = {{0,0,0,1},{1,0,0,1},{2,0,0,1}, // horizontals
                  {0,0,1,0},{0,1,1,0},{0,2,1,0}, // verticals
                  {0,0,1,1},{2,0,-1,1}};         // diagonals
char winner = '-';
for (int[] check : checks)
    if ((winner = checkWinner(board, check[0], check[1], check[2], check[3])) != '-')
private static char checkWinner(char[][] board, int y, int x, int dy, int dx) {
    char c = board[y][x];
    return (board[y + dy][x + dx] == c && board[y + dy * 2][x + dx * 2] == c ? c : '-');

Beginning Object-Oriented Programming with C#, To interact with them, however, still means you must climb down to their levels all the way down the ladder to make yourself present within the if statement With data items that are scoped, the magnitude of the problem shrinks immensely​. If  How Inventory Adjustments Affect Income Statements. The income statement is one of the three primary financial statements companies use to form a well-rounded view of their operating and financial health. The income statement records the financial and accounting numbers tied to your company's sale and profit

What about following approach. As I can see, you have limited number of winners: board[0][0], board[1][0], board[2][0], board[0][1], board[2][0]. You can create separate Predicate for each winnger with appropriate name.

Predicate<char[][]> isZeroOneWinner = new Predicate<char[][]>() {
    public boolean test(char[][] board) {
        return board[0][1] == board[1][1] && board[1][1] == board[2][1] && board[0][1] != '-';

I think is is better that multiple if...else.

How would you refactor nested IF Statements?, Then if the check fails, set the variable to false. How many different ways can this type of coding problem be refactored to reduce nesting and increase  i have done all of these tips and still my file size wouldn’t go down from 122mb! i had one table with no calculations (all pasted as values after my calculations are done). Then i stumbled across Name Manager and saw all the cell names are still stored and copied over from other workbooks, once deleted, i saved and closed it before reopening

Abridgment of the Debates of Congress, from 1789 to 1856: Dec. 4, , They condensed statement of the history of the negoknow what I have heard and if statements of fact wholly from the earliest period down to the comincorrect , are hear in all the contests inherent difficulty , in which no Administration of party But , sir , I importance , as transcending any other question shrink not from the  I want to have these drop-down lists copied all the way down in my dynamic table and when I add a new row below, these two drop-down lists would be auto-expanded. My problem is that the secondary drop-down list in the rows below the first row displays choices depending on the value selected in the primary drop-down in the first row.

Statement of the Executive Committee of the National Association , You can leave all the yolk in the wool , and the yolk is the waste in the wool . Mr . Lawrence : Such wool as that specimen would not shrink anything like as much as It was laid down in 1866 that 100 pounds of washed wool would yield 64  Excel logical formulas: 12 simple IF statements to get started Learn the ins and outs of the logical formulas like the famous IF Statements that represent the heart of Excel.

Keeping your code clean by sweeping out "if" statements, And so out I went to find alternative patterns to those if statements, Reducing Cyclomatic Complexity is vital to reduce bugs. I just leave a good comment, and all is well for my future self and my team down the road should  -Alcohol does not need to be digested before it can be absorbed.-Women absorb about one-third more alcohol than men because women have fewer stomach enzymes that break down the alcohol prior to absorption.-On an empty stomach, alcohol can be absorbed through the lining of the stomach.-All of these statements about alcohol are true.

  • Try using methods for each row/direction
  • What exactly do you mean?
  • huh? how is this supposed to work?
  • sorry i misred it, let me thinkg again
  • No but like... This won't really help me simply the code?
  • see now with a fuction, just move the code in the function