Break Statement in C++ Program

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

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:


Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , ,