Drycodez Posted August 20, 2011 Share Posted August 20, 2011 Is it wright to do something like this: date=new Date();h=date.getHours();if(h==1){execute this}if(h==2){execute that} when is the wright place to use else if this stuff is kinda confusing! Link to comment Share on other sites More sharing options...
jeffman Posted August 20, 2011 Share Posted August 20, 2011 That's exactly the kind of place to use an else if. It makes program execution more efficient and also reminds you, the developer, that you only want to execute one code block, not several. That makes it easy to remember what you want to happen. if (h == 1){ // execute this}else if (h == 2){ // execute that} Not using an else might imply to you, the developer, that a set of conditions could exist where both code blocks could be executed. This way, it's absolutely clear that that will never happen. Link to comment Share on other sites More sharing options...
Drycodez Posted August 20, 2011 Author Share Posted August 20, 2011 Thanks bro! Link to comment Share on other sites More sharing options...
thescientist Posted August 21, 2011 Share Posted August 21, 2011 . Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.