<!-- JavaScript:Arrays code snippet 5. -->
<!-- A 'for loop' and array structure. -->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- Code source: http://www.justfigures.co.uk/ -->
<!-- A resource for web developers using XHTML, CSS, JavaScript, PHP -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View code snippet page</title>
</head>

<body>
<script language="JavaScript" type="text/javascript">
//<![CDATA[
/* store data in an array and write data items 
back to the page with a 'for loop' */

// create an array of a predefined size to store 5 items
var markArray = new Array (5);
/* fill the array with student's marks by assignment to individual index value */
// note that an array index starts at 0
 markArray[0] = 85;
 markArray[1] = 96;
 markArray[2] = 50;
 markArray[3] = 45;
 markArray[4] = 63;

document.write('Confirmation of student\'s marks' + '<br />');
// note use of \ to escape the ' character
for (var mark = 0; mark < markArray.length; mark = mark + 1)
{
    document.write(markArray[mark] + '<br />')
}
//]]>
</script>

</body>
</html>