Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Several considerations may apply, depending on whether the conditions are mutually exclusive or not.</p> <p>If the conditions are mutually exclusive, the simplest solution is to group them by their return value:</p> <pre><code>if (condition1 || condition3 || condition4) return 1; if (condition2 || condition5) return 2; return 3; </code></pre> <p>If the conditions are not mutually exclusive, you can group together only the ones that are next to each other in the testing order:</p> <pre><code>if (condition1) return 1; if (condition2) return 2; if (condition3 || condition4) return 1; if (condition5) return 2; return 3; </code></pre> <p>Note that although you do not need an <code>else</code> after a return, it is common in some shops to include an <code>else</code> anyway. This is a matter of coding standardization which should be decided together by your coding team.</p> <p>If you would like to get really fancy, you can create an array of <a href="http://developer.apple.com/library/ios/#documentation/cocoa/Conceptual/Blocks/Articles/bxGettingStarted.html#//apple_ref/doc/uid/TP40007502-CH7-SW1" rel="nofollow"><em>blocks</em></a>, test conditions in order, and return the value returned by the block. This is by far the trickiest approach. It would significantly impair readability, unless the conditions are structured in the same way, and the code makes sense to the reader. Chains of <code>if</code>s always make sense to a reader, so it is very hard to compete on readability with them.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload