if statement - if/else coding style consequences -


i novice programmer , in lecture 1 evening, studying "if,else" coding section professor , curious aspect of it. curious if have bunch of nested if,else's in our program, bad coding style end if,else "else,if" line of code instead of if "x", else "y"? example,

if "x" else if "y" else if "z" end 

compared

if "x" else if "y" else "z" end 

it still run program without error, there consequences later on other having bad programming style?

behind curtain js dont have else if, doing generating if statement when parsed.

e.g:

if(foo){  } else if (baz){  } 

becomes

if (foo){  } else {    if (baz){     } } 

so reason using else if in end instead of else when want control else statement as-well , not pass case else don't fit in first condition... (in order control else condition , filter necessary items only)

if have long statement lot of else-if conditions should consider using switch statement instead.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -