2017-08-17 55 views
-5

我寫了一個代碼,它有一個for循環,代碼如下。但是當我構建代碼時,我得到'繼續不在循環內'。我無法理解爲什麼會發生這種情況。好心幫轉到錯誤:繼續不在一個循環中

轉到版本:

go version go1.7.5 linux/amd64

完整代碼在以下鏈接 https://pastebin.com/0ZypMYVK

參考截圖 enter image description here

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

錯誤enter image description here

./hashcode.go:88: continue is not in a loop

+3

這不太可能。在發佈之前你有多少次更改你的代碼? – zerkms

+4

請發帖[mcve]。 – bereal

+0

發佈的代碼不會觸發發佈的錯誤。 – Volker

回答

1

你的問題是在這裏:

//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循環,所以你會因此而分心,但這並不是在第86/87/88行附近的錯誤中沒有給出的行。如果問這樣的問題,最好在play.golang.org上發佈代碼。

+1

這就是我的一個很大的愚蠢......我應該刪除這個問題嗎? – Katiyman

+0

別擔心,我們都會這麼做,下一次嘗試讓別人可以嘗試複製,因爲這有助於降低成本。打倒這個問題是不幸的,我不知道爲什麼這成爲一種習慣。 –

+0

謝謝,下次發帖時我會記住建議。 – Katiyman