Actionscript Course

Break

break is an instruction that allows you to stop processing a loop (or "switch" conditional).
If you want to end a loop before its condition is false, you can use the break instruction after a conditional "if()".

Example:
var total:int = 1;

// create a for() loop
for(var i:int=0; i<4; i++)
{
  total *= 2;
  if(total==8) break;         // ends completely this loop
  trace('i='+ i+ ' - total='+ total);
}

// Output:  i=0 - total=2  i=1 - total=4
When the conditional "if(total==8)" returns true, the code after the "break" will not be executed at all, and the execution of this "for()" loop ends.
The Output panel displays:
i=0 - total=2
i=1 - total=4
- The condition (i<4) is still true, becouse the value of "i" is 1, but the "break;" instruction ends completely this loop.

Continue

The continue instruction skips the remaining statements in the current loop and begins the next iteration at the top of the loop.
The difference between "break" and "continue" is that the "break" statement ends completely the loop, while "continue" ends the current iteration only, and lets the loop to continue with the next iteration.

Example:
var total:int = 1;

// create a for() loop
for(var i:int=0; i<4; i++)
{
  total *= 2;

  // skip other actions in the current iteration when total==4 or total==8
  if(total==4 || total==8) continue;

  trace('i='+ i+ ' - total='+ total);
}
The Output is:
i=0 - total=2
i=3 - total=16
- Notice that when the value of "total" is 4 or 8, the trace() statement after the "continue" instruction is not executed, but the for() loop continue with the next iterations until its condition is false.

"break and "continue" can be used with any loop statement: while(), do..while, for(), for..in, for each..in.

Daily Test with Code Example

HTML
CSS
JavaScript
PHP-MySQL
Which HTML element can be used to embed a SWF flash content?
<object> <div> <script>
<object type="application/x-shockwave-flash" data="file.swf" width="500" height="250">
 <param name="src" value="file.swf" />
 Your browser not support SWF.
</object>
Which CSS pseudo-class adds a style to an input form field that has keyboard input focus?
:active :focus :hover
input:focus {
  background-color: #88fe88;
}
Click on the instruction which converts a JSON string into a JavaScript object.
JSON.stringify(javascript_object) object.toString() JSON.parse(json_string)
var jsnstr = '{"url": "http://coursesweb.net/", "title": "Web Development Courses"}';
var obj = JSON.parse(jsnstr);
alert(obj.url);
Indicate the PHP function which can be used to create or write a file on server.
fopen() file_put_contents() file_get_contents()
if (file_put_contents("file.txt", "content")) echo "The file was created";
else echo "The file can not be created";
Break and Continue

Last accessed pages

  1. Deco Tool (2730)
  2. Add /Delete rows in HTML table with JavaScript (4307)
  3. Align DIVs on the same line (8489)
  4. Highlight Images on click (6764)
  5. Get Mime Type of file or string content in PHP (6263)

Popular pages this month

  1. Courses Web: PHP-MySQL JavaScript Node.js Ajax HTML CSS (332)
  2. The Mastery of Love (38)
  3. CSS cursor property - Custom Cursors (38)
  4. PHP-MySQL free course, online tutorials PHP MySQL code (32)
  5. Read Excel file data in PHP - PhpExcelReader (29)