...

View Full Version : question on break statements



123altoids
11-07-2004, 03:30 PM
I am relativly new to programming, and have a question about break statements.

is there any way to create a break statement that will break you out of more than one loop, not just the one you are currently in?
or, is there any way to go from one point in a program to another, with having to write a if-else statement?

also, if i have this: while(ytotal<21 && deci!=s){
lot's of code....
}

if there any way to make the "s" a character, not a variable?

thanks, 123altoids

liorean
11-07-2004, 04:42 PM
Yes. Any kind of statement may have a label. They look like this:
label: statement
The label part must be a valid identifier, but it does not share namespace with any other type of identifier. Thus, you may have a label and a variable with the same name. The JavaScript engine will know when you are using the variable and when you are using the label.

The break statement looks like either of these:
break;
break label;

The first one can only be used in loops, and will abruptly terminate the directly enclosing loop or switch statement. The second one may be used inside the label statement with specified label, and will abruptly terminate the statement.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum