0

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"

asked Dec 21, 2013 at 15:19
1
  • 2
    Lets see your debug output as well please. Commented Dec 21, 2013 at 15:21

1 Answer 1

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
answered Dec 21, 2013 at 15:35
Sign up to request clarification or add additional context in comments.

1 Comment

See revised. You are best using an else if

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.