100 likes | 293 Views
JavaScript Loops. 17 April 2014. Creating Content . Putting Content within Tags. General form: c ontext.element.attribute form- name . input - id .value form- name . img - id .src document.getElementById (“ id ”). innerHTML. Loops . Looping. Want to be able to do things more than once
E N D
JavaScript Loops 17 April 2014
Putting Content within Tags General form: context.element.attribute form-name.input-id.value form-name.img-id.src document.getElementById(“id”).innerHTML
Looping • Want to be able to do things more than once • Basic: • for(vari=initial; while-clause; increment) { statement; } • Example: loop.html
Looping through an array • Attribute of an array: length • Because first entry is 0, loop while < length
Nesting Loops • When you need to work with two or more numbers • Examples • Creating a table • Computing the area of a range of rectangles • …
While • Want to end the loop based on some condition • Need to be changing something to cause it to end Test first: while (condition) { statements; } Test last: do{ statements; } while(condition);