Question

In: Computer Science

What does break and continue mean in C++?

What does break and continue mean in C++?

Solutions

Expert Solution

Break is a keyword used within a loop to abruptly exit from loop on a condition when holds true.

The condition can be anything as per the code requirement.

For example, add all the number and stop when user press -1.

So the code will be something like:

while(true)

{

cout<<"Enter a number ";

cin>>num;

if(num==-1) break; // Exit the loop

else

sum=sum+num;

}

___________________________________________________________

Continue keyword is used inside loop to go to next loop iteration if a certain condition holds true. Using continue keyword, all the statement after the keyword continue is ignored and loop goes to it's next iteration.

For example, add all positive integer entered by user.

for(int i=0; i<5;i++)

{

cout<<"Enter a number ";

cin>>num;

if(num<0) continue;

else sum+=num;

}

Now suppose user enters : 2 3 -6 1 -1

The sum will have value as : 6


Related Solutions

what is a const in C++? what does const mean in these functions
what is a const in C++?what does const mean in these functions-> " void idkwhattonameit( const name) {} "-> " void idkwhattonameit2( const &name) {} "-> " void idkwhattonameit3( const * name) {} "-> " void idkagain (const unique_ptr < Name > name_uPtr)"
What does this and *this mean in c++ And how to use them
What does this and *this mean in c++ And how to use them
What does the term performance mean? Expected performance? b. What does the term risk mean? c....
What does the term performance mean? Expected performance? b. What does the term risk mean? c. Can the risk be completely eliminated? Why? d. In the financial securities market, how can the level of risk be minimized? and. What does variability mean within corporate finance? F. What does the concept of diversification mean within corporate finance? What is its application within a global stock market?
what does this "->" mean in c? when can you use it?
what does this "->" mean in c? when can you use it?
Java Program // DO NOT USE BREAK OR CONTINUE :) You are allowed to use the...
Java Program // DO NOT USE BREAK OR CONTINUE :) You are allowed to use the following methods from the Java API: class String length charAt class StringBuilder length charAt append toString class Character any method CANNOT use break or continue moveXDownLeft takes a char and a two dimensional array of char as input and returns nothing: The method should find the first occurrence of the char in the array (searching from "top" to "bottom" and "left" to "right"), and...
In C++ what does it mean when it says: "error: stray '\226' inprogram"
In C++ what does it mean when it says: "error: stray '\226' in program"
What does it mean to have a good life? What does it mean to be a...
What does it mean to have a good life? What does it mean to be a good person?
What does it mean to be "modern" biologically and culturally? What does it mean to be...
What does it mean to be "modern" biologically and culturally? What does it mean to be human? Antropology 101
how does the break-even point fit into this discussion? What is the break-even point? Why is...
how does the break-even point fit into this discussion? What is the break-even point? Why is it an important concept in managerial accounting? What are its uses?
What is catalase? What reaction does catalase catalyze (i.e., what molecule does it break down, and...
What is catalase? What reaction does catalase catalyze (i.e., what molecule does it break down, and what is it broken down into)? Catalase breaks down toxic oxygen metabolites (such as H2O2), why is this important? Where do these toxic oxygen metabolites come from? Do anaerobes have catalase? Explain. What will you observe if you add hydrogen peroxide (H2O2) to catalase-positive bacteria? What will you see if it is catalase-negative? What type of bacteria are catalase-positive (aerobes, anaerobes, or facultative anaerobes...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT