-4
       } else {
            this.getSequenceDataWithPO(extractedData, extractedDateData);

        }
    }
    return hasbroData;
}

// Fetch data where po number is not null
/**
 * @param extractedData
 * @param extractedDateData
 * @return hasbroData
 */
private List<String> getSequenceDataWithPO(List<HasbroIssuanceAmmendExtractData> extractedData,
        List<HasbroIssuanceDateData> extractedDateData) {

I am trying to call getSequenceDataWithPO in else block. However while debuging when it get to else block it does not excute the method. what am i doing wrong?

5
  • Could you share a bit more code ? Does it enters the if block ? Have you set a breakpoint inside getSequenceDataWithPO() method ?
    – Gaël J
    Jan 5, 2016 at 15:17
  • 3
    Please edit your question with a minimal reproducible example or SSCCE (Short, Self Contained, Correct Example) Jan 5, 2016 at 15:19
  • @Gaël yes it enter if block. and as soon it reach else block ...it goes back again to if. Yes i had set up break point over there as well. but never execute getSequenceDataWithPO
    – Sam
    Jan 5, 2016 at 15:20
  • 2
    @Sam : if it enters the if block , why do you expect it to enter the else block ?! It's one or the other, not both...
    – Gaël J
    Jan 5, 2016 at 15:26
  • @Gaël Yes you are rite....it is doing its if part correct. However once it is in else condition in a different case it should execute that method. which is not happening.
    – Sam
    Jan 5, 2016 at 15:35

1 Answer 1

0

if, else if, and else statements should be thought of like this:

if: if the following conditions are met, then execute these commands

else if: otherwise and if the following conditions are met, then execute these commands

else: otherwise, execute the following commands

This means that conditional statements are executed in a chain. Once one of the conditions in an if, else if, and else chain is met, none of the other conditional statements are processed. Since your else block is not being executed, then you probably already met a previous if or else if statement's conditions. In order to check for two conditions independent of each other, simply use two separate if statements.

For example, in the code below, the word "World" and the "!" will not be printed, even though it is true that 5 is greater than 2 and that 4 is greater than 1:

if (5 > 2)
    System.out.print("Hello, ");
else if (4 > 1)
    System.out.print("World");
else
    System.out.print("!");

But, in the next example, both "Hello, " and "World" and "!" will be printed, because the three conditionals are independent of each other:

if (5 > 2)
    System.out.print("Hello, ");
if (4 > 1)
    System.out.print("World");
if (0 == 0)
    System.out.print("!");

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.