Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Break Statement | Control Structures
Вступ до Golang

bookBreak Statement

The break keyword can be used to prematurely exit a loop, even if it has not reached its stop condition.

Here's an example of how break can be used inside a loop:

index.go

index.go

copy
123456789101112
package main import "fmt" func main() { for i := 1; i <= 5; i++ { fmt.Println(i) if i == 3 { break } } fmt.Println("Loop ended") }

The provided code terminates the loop when i==3 instead of i==5. Any code after the break statement within the loop is automatically ignored since the loop breaks at that specific point.

The break keyword, also referred to as the break statement, can be a valuable tool for controlling the loop's flow. It enables you to impose additional conditions within the loop.

question mark

Which lines will be included in the output of the following code?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 7

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Suggested prompts:

Can you show me an example of using the break statement in a loop?

What is the difference between break and continue in a loop?

Are there any best practices for using break in loops?

Awesome!

Completion rate improved to 1.96

bookBreak Statement

Свайпніть щоб показати меню

The break keyword can be used to prematurely exit a loop, even if it has not reached its stop condition.

Here's an example of how break can be used inside a loop:

index.go

index.go

copy
123456789101112
package main import "fmt" func main() { for i := 1; i <= 5; i++ { fmt.Println(i) if i == 3 { break } } fmt.Println("Loop ended") }

The provided code terminates the loop when i==3 instead of i==5. Any code after the break statement within the loop is automatically ignored since the loop breaks at that specific point.

The break keyword, also referred to as the break statement, can be a valuable tool for controlling the loop's flow. It enables you to impose additional conditions within the loop.

question mark

Which lines will be included in the output of the following code?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 3. Розділ 7
some-alt