Complete the code to create an infinite loop that prints "Hello" repeatedly.
package main import "fmt" func main() { for [1] { fmt.Println("Hello") } }
false which never runs the loop.Using true in the for loop condition creates an infinite loop in Go.
Complete the code to create an infinite loop using the classic for loop syntax.
package main import "fmt" func main() { for [1] { fmt.Println("Looping forever") } }
In Go, a for loop with empty initialization, condition, and post statements (for ;;) runs infinitely.
Fix the error in the infinite loop code so it compiles and runs correctly.
package main import "fmt" func main() { for [1] { fmt.Println("Running") } }
True instead of lowercase true.for inside the loop condition.Go uses lowercase true for boolean true. Using True causes a compile error.
Fill both blanks to create an infinite loop that prints numbers starting from 1.
package main import "fmt" func main() { i := 1 for [1] { fmt.Println(i) i[2] } }
++ which is a statement, not an expression.-- which decreases the number.The loop condition true makes the loop infinite. Using i += 1 increases i by 1 each time.
Fill all three blanks to create an infinite loop that prints "Go!" every second.
package main import ( "fmt" "time" ) func main() { for [1] { fmt.Println([2]) time.Sleep([3]) } }
false which stops the loop immediately.time package.The loop condition true makes it infinite. Printing "Go!" shows the message. time.Sleep(time.Second) pauses for one second each loop.