Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

break;

Status
Not open for further replies.

thibault

Programmer
Sep 8, 1999
44
US
what's up with break.&nbsp;&nbsp;not only does it not work &quot;anywhere&quot;, but it creates a script error so that, when i use it, nothing works.&nbsp;&nbsp;&nbsp;&lt;grumble grumble&gt; <p>bobbie<br><a href=mailto:thibault@hotbot.com>thibault@hotbot.com</a><br><a href= </a><br>
 
thibault,<br><br>can you post your code? I'm not sure why the break isn't working in your case.. <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
here is the code.&nbsp;&nbsp;the book said i could use break in any loop.&nbsp;&nbsp;in the example, however, they only used it in a for loop.&nbsp;&nbsp;i created a do/while loop and named it checkAssoc.&nbsp;&nbsp;it doesn't work.&nbsp;&nbsp;i've studied it for errors, but can't find any.<br>ps: the entire app works fine when i comment out the checkAssoc loop.<br><br>&nbsp;&nbsp;&nbsp;function checkValue() { // check for null field value<br><br> checkAssoc:<br> do {<br> val = window.eval(&quot;document.frmOrder.Assoc.focus()&quot;);<br> alert(&quot;A value must be entered in the Associate Name field.&quot;);<br> return false;<br> } while (document.frmOrder.Assoc.value.length &lt; 1);<br> break checkAssoc;<br><br> if (document.frmOrder.Guest.value.length &lt; 1) {<br> val = window.eval(&quot;document.frmOrder.Guest.focus()&quot;);<br> alert(&quot;A value must be entered in the Customer Name field.&quot;);<br> return false;<br> }<br> else {<br> submitIt(); <br> }<br>} <p>bobbie<br><a href=mailto:thibault@hotbot.com>thibault@hotbot.com</a><br><a href= </a><br>
 
Holly Syntax Batman... what is that!<br><br>&gt; checkAssoc:<br>&gt; break checkAssoc;<br><br>Does javascript support 'lables'? Can someone confirm this for me, either way please, I would like to be sure. Thanks in advance.<br><br>Anyway bobbie,<br><br>Your code does not really make any sense. The 'break' statement will cause processing to continue on the next code line beyond the current block scope. Normally there is a condition associated with a break statement, I don't see one in your code.<br><br>var str = new String(&quot;hello world\n&quot;);<br>var ipos = 0;<br>var firstword = new String(&quot;&quot;);<br>// next line of code begins a 'block scope'<br>while ( str.charAt(ipos) != '\n'){<br><br>&nbsp;&nbsp;if ( str.charAt(ipos) == ' ') // when the character is a space<br>&nbsp;&nbsp;&nbsp;&nbsp;break;&nbsp;&nbsp;// break out of the 'while' block scope<br><br>&nbsp;&nbsp;firstword += str.charAt(ipos++);<br>}<br><br>alert( firstword); // the break statement will cause the flow of control to 'jump' to this line<br><br>The function body is not considered a 'block scope' in terms of the 'break' statement, if you want the flow of control to leave the entire function then you use the 'return' statement not the 'break' statement.<br><br>Hope this helps<br>-pete<br>
 
well Java does support labels in a sense (it's reserved &quot;goto&quot;, horror of horrors, but only uses labels for breaking and continuing), so I wouldn't be surprised if JavaScript did... but my God, never use them!! At least not if you can help it.<br><br>Read up on &quot;goto considered harmful&quot;... <p>Liam Morley<br><a href=mailto:lmorley@wpi.edu>lmorley@wpi.edu</a><br><a href=] :: imotic :: website :: [</a><br>"light the deep, and bring silence to the world.<br>
light the world, and bring depth to the silence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top