错误:继续不在循环中

卡蒂曼:

我已经编写了具有for循环的go代码,下面给出了代码。但是当我构建代码时,我得到“继续不在循环内”。我不明白为什么会这样。请帮助

转到版本:

go版本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不在循环中

肯尼·格兰特(Kenny Grant):

您的问题在这里:

//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)
}

该错误说明了出了什么问题。当您不在for循环中时,您正在使用关键字continue,该函数不包含for循环。

initCodeLedger包含一个for循环,因此您会因此而分心,但这不是错误所在的行no,它位于第86/87/88行附近。如果问这样的问题,最好在play.golang.org上发布代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章