What is a break statement?


#1



https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/4?curriculum_id=506324b3a7dffd00020bf661


Oops, try again. Make sure to use a break statement with each case!


var boss = prompt("Do you want to raid the pension fund, take over a company, or become a Marine?").toLowerCase();

switch (boss){
    case'raid': 
        var stealthy = prompt("Is your CPA stealthy (Yes or No)?").toLowerCase();
        var ethics = prompt("Do you have any ethics (Yes or No)?").toLowerCase();
        if(stealthy=='Yes'&&ethics=='No') {
            console.log("GREAT! That is a perfect combination!");
        } else { 
            console.log("Sorry, you must have already given up ethics.  Maybe                      another time.");
        }
    break;
    case'take': 
        var identified = prompt("Have you identified (Yes or No) your target?").toLowerCase();
        var offer = prompt("Have you made an offer (Yes or No)?").toLowerCase();
        if(identified=='yes'||offer=='no'){
        console.log("Good, you have a start.");
        
        } else {
          console.log("To take over a company, you have to decide which company and               make an offer.");
        }
    break;
    case'Marine':
        var strong = prompt("Are you strong (Yes or No)?").toLowerCase();
        var blues = prompt("Do you look good in dress blues (Yes or No)").toLowerCase();
    default: 
        console.log("I'm not sure what you are choosing.  Click RUN and select raid the pension fund, take over a company, or become a Marine."); 
    }


#2

@lodum

After each of your case, you must put a break;


#3

A break statement tells to avoid checking the cases that follow up if an earlier case is already satisfied . If none of the case matches then the default is executed . So it is mandatory to use break statement in switch


#4

Is a semi-colon ; the break? I have one but it ran over to the second line. How can I indicated that text has run over onto another line but is part of the whole statement?


#5

@lodum

It's the same statement but because the editor of codeacademy is not big enough, the semicolon will go to the next line but it is part of the statement.


#6

OK, thanks! I can quit worrying about that!


#7

I think semi colon is only a line break it is not same as the case break; in switch statements


#8

Then what is a case break?


#9

Like I said before break; in a switch indicates the end of the case , meaning that the set of statements to be executed if the case is true is over and tells the control to exit the switch statement .