i've a problem with a couple of if-else conditions, here's the code:
if((hour<=16 && min<30)||(hour>=21 && min>0))
{ //copy of if#3
Log.d("baja", "copy");
message="something2";
}
if ((day>=1 && month>=4) && (day<=30 && month<=9))
{ //if#1
if((hour<=16 && min<30)||(hour>=23 && min>0))
{ //if#2
message="something";
}
}//end of if#1
else
{ //else for if#1
Log.d("baja", "before if#3 ");
if((hour<=16 && min<30)||(hour>=21 && min>0)){ //if#3
Log.d("baja", "if#3");
message="something2";
}
}
the problem is that if the flow enters the else if#3 doesn't work, but the copy i've put outside if#1 works perfectly....what is the problem?
i can't post the exact log now, but i can see "copy" and "before if#3"
-
2Lets see your debug output as well please.span– span2013年12月21日 15:21:32 +00:00Commented Dec 21, 2013 at 15:21
1 Answer 1
I think I know what you are trying to do (If I understand your question correctly). The reason for this is that the else block is attached to the high level if block, rather than it's internal logic. If the if#1 returns false, nothing will happen, if it is true it will test if#2 -> if this is false, it will execute the else statement. If this is not your question, please supply the stack trace as rattmuff requested
if ((day>=1 && month>=4) && (day<=30 && month<=9))
{
if((hour<=16 && min<30)||(hour>=23 && min>0))
{
message="something";
}//if#2
else
{
Log.d("baja", "before if#3 ");
}//else
}//if#1
else if((hour<=16 && min<30)||(hour>=21 && min>0))
{
Log.d("baja", "if#3");
message="something2";
}//if#3