170 likes | 261 Views
Learn the Big Six concepts - data types, storage, retrieval, repetition, decision-making, procedure & data abstraction with nested loops in JavaScript. Explore arrays, objects, and nested loops, critical for mastering programming concepts. Understand the inner and outer loop dynamics, iteration and indentation, crucial for code readability. Dive into the fabulous world of programming with practical examples and clear explanations. Enhance your skills in JavaScript programming with a focus on data abstraction and loop structures.
E N D
Introduction to Programming(in JavaScript) David Stotts Computer Science Department UNC Chapel Hill
The Big Six(6) Data Abstraction 0. data (types, simple information) 1. data storage (variables, assignment) 2. data retrieval (expressions, evaluation) 3. repetition (loops) 4. decision making (conditionals) 5. procedure abstraction (functions) 6. data abstraction (arrays) 7. objects: all-the-above, wrapped up
Loop Body Contains any valid statements… • assignment • conditionals for (i=0; i<length; i++) { sum = sum + grade[ i ] ; if (grade[i]>90) { aCount = aCount + 1; } }
What if loop body contains… Another complete loop?
Loops in Loops • We call them “nested ” loops
Nested For Loops for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . } . . . } inner loop, enclosed in outer outer loop, enclosing
Anyone from DC? This is the fabulous Capital Beltway...
Capital Beltway • A.K.A...
Nested For Loops for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . } . . . } inner loop outer loop
Nested For Loops for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . } . . . } many inner iterations inner loop outer loop 1 outer iteration
A Note on Indentation Formatting is CRITICAL for comprehension for (i=0; i<length; i++) { sum = sum + grade[ i ] ; if (grade[i]>90) { aCount= aCount + 1; } else { bfCount= bfCount + 1; } total += 1; }
A Note on Indentation Indent, block structure, be consistent for (i=0; i<length; i++) { sum = sum + grade[ i ] ; if (grade[i]>90) { aCount= aCount + 1; } else { bfCount++; } total += 1; }