Top Banner
David Stotts Computer Science Department UNC Chapel Hill Introduction to Programming (in JavaScript)
17

Introduction to Programming (in JavaScript)

Mar 22, 2016

Download

Documents

jubal

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 ) - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Programming (in JavaScript)

David StottsComputer Science Department

UNC Chapel Hill

Introduction to Programming

(in JavaScript)

Page 2: Introduction to Programming (in JavaScript)

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

The Big Six(6) Data Abstraction

Page 3: Introduction to Programming (in JavaScript)

We have been studying Arrays

Page 4: Introduction to Programming (in JavaScript)

We have seen “for loops” as access patterns

Page 5: Introduction to Programming (in JavaScript)

Contains any valid statements…◦ assignment◦ conditionals

for (i=0; i<length; i++) { sum = sum + grade[ i ] ; if (grade[i]>90) { aCount = aCount + 1; } }

Loop Body

Page 6: Introduction to Programming (in JavaScript)

Another complete loop?What if loop body contains…

Page 7: Introduction to Programming (in JavaScript)

Loops in Loops

We call them “nested ” loops

Page 8: Introduction to Programming (in JavaScript)

for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . }

. . . }

Nested For Loops

outer loop, enclosing

inner loop, enclosed in outer

Page 9: Introduction to Programming (in JavaScript)

Anyone from DC?

This is the fabulous Capital Beltway...

Page 10: Introduction to Programming (in JavaScript)

A.K.A...

Capital Beltway

Page 11: Introduction to Programming (in JavaScript)

The “Inner Loop”

Page 12: Introduction to Programming (in JavaScript)

and the “Outer Loop”

Page 13: Introduction to Programming (in JavaScript)

Inner and Outer Loops

Page 14: Introduction to Programming (in JavaScript)

for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . } . . .

}

inner loop

outer loop

Nested For Loops

Page 15: Introduction to Programming (in JavaScript)

for (i=0; i<length; i++) { . . . for (k=i; k<length; k++) { . . . } . . .

}

inner loop

outer loop

Nested For Loops

1 outer iteration

many inner iterations

Page 16: Introduction to Programming (in JavaScript)

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

Page 17: Introduction to Programming (in JavaScript)

Indent, block structure, be consistentfor (i=0; i<length; i++) { sum = sum + grade[ i ] ; if (grade[i]>90) { aCount = aCount + 1; } else { bfCount++; } total += 1;}

A Note on Indentation