Java For Loop Unreachable Code

时间:2017-11-16 15:50:22

标签: java for-loop unreachable-code

我的代码中有一个for循环,它给整个循环本身一个错误,说它是"无法访问的代码"。我完全不确定这个循环导致了什么:

To enable debugging of unmanaged code

它在

之后声称整个for循环
public ArrayList<Double> Update(ArrayList<Double> addInputs) 
{
// stores the resultant outputs from each layer

ArrayList<Double> outputs = null;

int cWeight = 0;

// first check that we have the correct amount of inputs

if (addInputs.size() != numInputs);
{
    // just return an empty vector if incorrect
    return outputs;
}

// For each layer....


for (int i = 0; i < numHiddenLayers + 1; ++i)
{
    if (i > 0)
    {
        addInputs = outputs;
    }

    outputs.clear();

    cWeight = 0;

    // for each neuron sum the (inputs * corresponding weights) .Throw

    // the total at our sigmoid function to get the output.

    for (int j = 0; j < neuronLayers.get(i).numNeurons; ++j)
    {
        double netinput = 0;

        int numberInputs = neuronLayers.get(i).listNeurons.get(j).numInputs;

    // for each weight

    for (int k = 0; k < numberInputs - 1; ++k)
    {
        // sum the weights x inputs

        netinput += neuronLayers.get(i).listNeurons.get(j).weights.get(k) *
                addInputs.get(cWeight++);
    }

    // add in the bias

    netinput += neuronLayers.get(i).listNeurons.get(j).weights.get(numberInputs - 1)
            *  dBias;

    // we can store the outputs from each layer as we generate them.

    // the combined activation is first filtered through the sigmoid

    //function

    outputs.add(sigmoid(netinput,dActivationResponse));
    }
}

是无法访问的代码。任何帮助将不胜感激。

3 个答案:

答案 0 :(得分:3)

此处有分号,因此该方法始终返回outputs。只需删除它

if (addInputs.size() != numInputs); // <---- this one
{
    // just return an empty vector if incorrect
    return outputs;
}

答案 1 :(得分:1)

if:

结尾处有一个分号
... != numInputs);

意味着它下面的返回将始终发生,使其下的代码无法访问。

删除分号。

答案 2 :(得分:0)

这是因为if condition因分号而终止

所以return将始终执行哪个传输控制到调用函数跳过你的其余代码