diff --git a/transpile/service.go b/transpile/service.go index 548774f..ccfee17 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -545,13 +545,19 @@ func handleForStmt(stmt *ast.ForStmt) string { code += handleStmt(stmt.Init, true) code += ";" } - code += handleBinaryExpr(stmt.Cond) // stmt.Cond + + if stmt.Cond != nil { + code += handleBinaryExpr(stmt.Cond) + } else { + code += "1" + } + if !is_while { code += ";" code += handleStmt(stmt.Post, true) } code += ") {" - code += handleBlockStmt(stmt.Body) // stmt.Body + code += handleBlockStmt(stmt.Body) code += "}" return code } diff --git a/transpile/service_test.go b/transpile/service_test.go index 322f8d4..601ceea 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -790,6 +790,27 @@ var _ = Describe("Go Translator", func() { }) Describe("Циклы", func() { + It("for {}", func() { + source := `package test + func Loop() { + var i int + for { + i = i + } + } + ` + expected := ` + void loop(); + + void loop() { + int i; + while (1) { + i = i; + } + } + ` + Compare(source, expected) + }) It("for i=0; i<10; i+=1", func() { source := `package test func Setup() {}