Search code examples
javacompiler-errorsunreachable-code

Java:Unreachable statement error


for the following code mentioned below ,I have been obtaining the Error " Unreachable statement error " at " Return Cols " statement

The code computes the position of Maximum Dose in a generated Output CSV file

public int getPosition() {

        double dose = 0.0;
        double position = 0.0;
        int rows = 0;
        int cols = 0;

        String s;

        for (int j = 1; j < nz; j++) {
            s = "";
            for (int i = 1; i < nx; i++) {
                for (DetEl det_el : det_els) {
                    if (det_els.get(j + i * nz).getDose() == getMaxDose()) {
                        i=rows;
                        j=cols;
                    }
                    // comma separated or Semicolon separated mentioned here
                }
                // prints out the stream of  values in Doses table separated by Semicolon
            }
        }
        return rows;
        return cols;//unreachable statement error obtained at this position.
    }

Any help is greatly appreciated


Solution

  • You have already breaked from the code using return rows;. This statement returns to the caller. So, a statement after return rows; is inaccessible