• Post Reply Bookmark Topic Watch Topic
  • New Topic

repeated if statements versus if-else statements  RSS feed

 
kambar bek
Greenhorn
Posts: 23
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , i ve been programming for 3 years now , but i still have this question:

suppose my code looks like this:




how is code above diff from this below:



is there any difference? i suspect no
 
Jayesh A Lalwani
Rancher
Posts: 2762
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's differrent if it is possible to satisfy 2 if conditions at the same time. Try this



and this



 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Erjan Kenjegalee wrote:hi , i ve been programming for 3 years now , but i still have this question:

suppose my code looks like this:




how is code above diff from this below:



is there any difference? i suspect no



Another way to envision this... if you take the second example, and consistently make both the if and the else block with braces, you get this...



At which point, you can easily see the difference.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!