0
0
Goprogramming~10 mins

Nested loops in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print numbers from 1 to 3 using a loop.

Go
for i := 1; i <= [1]; i++ {
    fmt.Println(i)
}
Drag options to blanks, or click blank then click option'
A0
B5
C3
D10
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 0 or 10 instead of 3 in the loop condition.
Forgetting to use <= instead of <.
2fill in blank
medium

Complete the code to print a 3x3 grid of stars using nested loops.

Go
for i := 0; i < 3; i++ {
    for j := 0; j < [1]; j++ {
        fmt.Print("*")
    }
    fmt.Println()
}
Drag options to blanks, or click blank then click option'
A5
B3
C4
D2
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using a different number than 3 for the inner loop.
Using <= instead of < causing extra stars.
3fill in blank
hard

Fix the error in the nested loops to print numbers 1 to 3 in each row.

Go
for i := 1; i <= 3; i++ {
    for j := 1; j <= [1]; j++ {
        fmt.Print(j, " ")
    }
    fmt.Println()
}
Drag options to blanks, or click blank then click option'
A4
B5
C0
D3
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 5 or 4 causing extra numbers.
Using 0 causing no output.
4fill in blank
hard

Fill both blanks to create a multiplication table from 1 to 3.

Go
for i := 1; i <= [1]; i++ {
    for j := 1; j <= [2]; j++ {
        fmt.Printf("%d ", i*j)
    }
    fmt.Println()
}
Drag options to blanks, or click blank then click option'
A3
B5
C4
D2
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using different numbers for the two loops.
Using numbers larger than 3 causing bigger tables.
5fill in blank
hard

Fill all three blanks to print a right triangle of stars with 3 rows.

Go
for i := 1; i <= [1]; i++ {
    for j := 1; j <= [2]; j++ {
        if j <= [3] {
            fmt.Print("*")
        }
    }
    fmt.Println()
}
Drag options to blanks, or click blank then click option'
Ai
B3
Cj
D5
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using j instead of i in the if condition.
Using wrong loop limits causing incorrect triangle size.