英文:
Go Error: continue is not in a loop
问题
我已经写了一个有一个for循环的Go代码,代码如下所示。但是当我构建代码时,我得到了"continue is not within loop"的错误。我不明白为什么会发生这种情况。请帮忙看看。
Go版本:
go version go1.7.5 linux/amd64
完整的代码在下面的链接中:
https://pastebin.com/0ZypMYVK
for k:=0;k < len(args);k++{
fmt.Println("k is ", k)
hsCode := args[k]
lenChk:=checkHashLen(hsCode)
if lenChk==false {
fmt.Println("Length should be 32" )
continue
}
codeBytes,_ := json.Marshal(hsCode)
APIstub.PutState(strconv.FormatInt(makeTimestamp(),10), codeBytes)
fmt.Println("Added: ", k)
}
./hashcode.go:88: continue is not in a loop
英文:
I have written go code which has a for loop, code is given below. but when i build the code i get 'continue is not within loop'. i can't understand why this is happening. Kindly help
Go Version:
> go version go1.7.5 linux/amd64
Complete Code at the below link
https://pastebin.com/0ZypMYVK
for k:=0;k < len(args);k++{
fmt.Println("k is ", k)
hsCode := args[k]
lenChk:=checkHashLen(hsCode)
if lenChk==false {
fmt.Println("Length should be 32" )
continue
}
codeBytes,_ := json.Marshal(hsCode)
APIstub.PutState(strconv.FormatInt(makeTimestamp(),10), codeBytes)
fmt.Println("Added: ", k)
}
答案1
得分: 1
你的问题在这里:
//将单个代码推送到区块上
func (s *SmartContract) pushCode(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {
hsCode := args[0]
lenChk := checkHashLen(hsCode)
if lenChk == false {
fmt.Println("长度应为32")
continue
}
codeBytes, _ := json.Marshal(hsCode)
APIstub.PutState(strconv.FormatInt(makeTimestamp(), 10), codeBytes)
return shim.Success(nil)
}
错误解释了出了什么问题。你在不在for循环中使用了关键字continue,而这个函数中没有for循环。
initCodeLedger包含一个for循环,所以你被那个分散了注意力,但是错误给出的行号并不在那个位置,而是在第86/87/88行附近。如果像这样提问,请在play.golang.org上发布代码。
英文:
Your problem is here:
//push single code on the block
func (s *SmartContract) pushCode(APIstub shim.ChaincodeStubInterface, args []string) sc.Response {
hsCode := args[0]
lenChk := checkHashLen(hsCode)
if lenChk == false {
fmt.Println("Length should be 32")
continue
}
codeBytes, _ := json.Marshal(hsCode)
APIstub.PutState(strconv.FormatInt(makeTimestamp(), 10), codeBytes)
return shim.Success(nil)
}
The error explains what is going wrong. You're using the keyword continue when not in a for loop, this function doesn't contain a for loop.
initCodeLedger contains a for loop, so you are getting distracted by that, but that's not the line no given in the error which is around line 86/87/88. Ideally post code on play.golang.org if asking a question like this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论