{"id":5825,"date":"2014-04-07T09:31:50","date_gmt":"2014-04-07T09:31:50","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/how-can-i-use-or-in-an-if-statement-in-java-without-having-to-retype-the-whole-expression-collection-of-common-programming-errors\/"},"modified":"2014-04-07T09:31:50","modified_gmt":"2014-04-07T09:31:50","slug":"how-can-i-use-or-in-an-if-statement-in-java-without-having-to-retype-the-whole-expression-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/07\/how-can-i-use-or-in-an-if-statement-in-java-without-having-to-retype-the-whole-expression-collection-of-common-programming-errors\/","title":{"rendered":"How can I use &ldquo;or&rdquo; in an if statement in Java without having to retype the whole expression?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m writing code for a minesweeper project for class and one method is numAdjMines, which counts the mines around a cell in the array, each type of cell has a different value, like mines are -2, while mines with a flag on them are -4. I want to just write one if statement, but I end up having to just write the same code twice, with different values at the end.<\/p>\n<pre><code>if (row &gt;= 1 &amp;&amp; col &gt;= 1 &amp;&amp; boardArray[row - 1][col - 1] == MINE)\n    {\n        adjMines = adjMines + 1;\n    }\nif (row &gt;= 1 &amp;&amp; col &gt;= 1 &amp;&amp;\n            boardArray[row - 1][col - 1] == FLAGGED_MINE)\n    {\n        adjMines = adjMines + 1;\n    }\n<\/code><\/pre>\n<p>I tried using || for or and writing || boardArray[row-1][col-1] == FLAGGED_MINE at the end of the first one, but that then ignored the beginning with checking the row and column. Is there a short compact way for me to write this code?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m writing code for a minesweeper project for class and one method is numAdjMines, which counts the mines around a cell in the array, each type of cell has a different value, like mines are -2, while mines with a flag on them are -4. I want to just write one if statement, but I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5825","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5825","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5825"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5825\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}