John
John

Reputation: 3

Having problems with 'Dead Link'

In my TRIANGLE class, I have a collection of if-else statements that check the validity of the shape (not all three points are on the same plane). The problem is that in my APPLICATION class (under Triangle portion), it is saying that my if-else statement, with the print statement saying if it is valid or not, is a 'dead link.' After Googling it, I understand that it means the else block will never be used and that's why it is a dead link. I am not sure why it wouldn't be used. I check over my if-else statement in both classes, and it seems like they make sense. Can you tell me what I am doing wrong?

The applicable code:

if (true){
    System.out.println("This circle shape you entered does pass the validity check.");
}
else {
    System.out.println("This circle shape you entered does not pass the validity check.");
}

Complete code.

Upvotes: 0

Views: 57

Answers (2)

hexacyanide
hexacyanide

Reputation: 91769

In your code, you have multiple if (true) statements. The code in your else statement is dead because it will never run:

if (true) {
  // do something
}
else {
  // do another something
}

An if statement runs if the supplied condition is true. true always happens to be true, so the else has no case where it will ever run.

Upvotes: 1

nanofarad
nanofarad

Reputation: 41281

if (true){
     System.out.println("This circle shape you entered does pass the validity check.");
}
else {
    System.out.println("This circle shape you entered does not pass the validity check.");
}

The first branch (if(true)) is always taken when reached. The else would thus never have a chance to run, resulting in dead code. Change if(true) to an actual validity check or remove the else portion.

Upvotes: 1

Related Questions