Break Statement in C++ Program

| Last Updated: | In: C++ Tutorial


In this tutorial, I will explain how to use the break and continue in c++ programming language. The break is typically used in the context of a switch statement. Below is the standard switch statement with the break. This tutorial will explain you about the break statement in C++ program. After going through of this tutorial, you will able to know:

  1. What is a break statement?
  2. How to use break statement?
  3. How to write program using the break statement?

What is a break statement?

The break statement is used inside a loop, the loop is immediately terminated when we call the break statement in the program. The break statement mostly used with the switch statement.

How to use break statement?

Below example will show you how to use the break statement in your program while you are using the switch statement.

How to write program using the break statement?

Below is the program which prints the day name when the user enters number during this below program. If the user enters 1, then the output is “Today is Monday” and when enter 5, the output will be “Today is Friday”. If user enter number beyond the between 1 to 7, then the output will be the “Invalid number”.

Output:

//First try
1
Today is Monday
//Second Try
5
Today is Friday
//Third try
9
Invalid number


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:

Tags: , , ,