Java For 循环无法访问的代码
Java For Loop Unreachable Code
我的代码中有一个 for 循环,它在整个循环本身上给出错误,说它是 "unreachable code"。我完全不确定是什么导致了这个循环:
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));
}
}
它在
之后声明了整个for循环
// For each layer....
是无法访问的代码。任何帮助将不胜感激。
这里有一个分号,所以方法总是返回 outputs
。删除它
if (addInputs.size() != numInputs); // <---- this one
{
// just return an empty vector if incorrect
return outputs;
}
你的 if:
末尾有一个分号
... != numInputs);
意味着它下面的 return 将 总是 发生,使得它下面的代码无法访问。
删除分号。
意思是因为if condition
因为分号
而终止
因此 return
将始终执行哪个将控制权转移给调用者函数,从而跳过其余代码
我的代码中有一个 for 循环,它在整个循环本身上给出错误,说它是 "unreachable code"。我完全不确定是什么导致了这个循环:
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));
}
}
它在
之后声明了整个for循环// For each layer....
是无法访问的代码。任何帮助将不胜感激。
这里有一个分号,所以方法总是返回 outputs
。删除它
if (addInputs.size() != numInputs); // <---- this one
{
// just return an empty vector if incorrect
return outputs;
}
你的 if:
末尾有一个分号... != numInputs);
意味着它下面的 return 将 总是 发生,使得它下面的代码无法访问。
删除分号。
意思是因为if condition
因为分号
因此 return
将始终执行哪个将控制权转移给调用者函数,从而跳过其余代码