Created
January 9, 2018 03:20
-
-
Save anacrolix/d5cb2dbc50ebbc167187fa439998d4bb to your computer and use it in GitHub Desktop.
condition style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// which would you do? comment below | |
// distinct ifs | |
if n == 1 { | |
single() | |
} | |
if n > 1 { | |
multi() | |
} | |
// else if | |
if n == 1 { | |
single() | |
} else if n > 1 { | |
multi() | |
} | |
// switch | |
switch { | |
case n == 1: | |
single() | |
case n > 1: | |
multi() | |
} |
single is called if n is 1, and multi if n is > 0, and three if n == 3.
typo that mutli is called if n > 0 :)
context is needed, as should multi and three both be called if n == 3?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plus the logic does not become entangled.
single
is called if n is 1, andmulti
if n is > 0, andthree
if n == 3.