Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
break statement | Loops
C# Basics

break statementbreak statement

The break statement is used for breaking / stopping a loop mid-execution. It is useful in cases where we want to stop a loop in case some additional condition is met.

Following is an example of the break statement being used in the for-loop:

cs

main.cs

The above code outputs i till 5 and then the loop stops. This is because of the additional conditional break we added.

We can also use the break statement in other loops:

cs

main.cs

The loop we constructed above works exactly the same as the for-loop we looked at before. The break statement can be used in the do-while loops as well. The break statement is very useful in adding additional conditions to a loop.

How many iterations will the loop run for?

Виберіть правильну відповідь

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

Секція 4. Розділ 6
course content

Зміст курсу

C# Basics

break statementbreak statement

The break statement is used for breaking / stopping a loop mid-execution. It is useful in cases where we want to stop a loop in case some additional condition is met.

Following is an example of the break statement being used in the for-loop:

cs

main.cs

The above code outputs i till 5 and then the loop stops. This is because of the additional conditional break we added.

We can also use the break statement in other loops:

cs

main.cs

The loop we constructed above works exactly the same as the for-loop we looked at before. The break statement can be used in the do-while loops as well. The break statement is very useful in adding additional conditions to a loop.

How many iterations will the loop run for?

Виберіть правильну відповідь

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

Секція 4. Розділ 6
some-alt