VNUHCM
Previous lesson Next lesson
  • Learning content
  • Help
    Do you have any questions while learning?
    Learning instructions Frequently asked questions Email for support
    • Tiếng Việt
    • English
    • Member's information
    • Registered courses
    • Log out
  • Cohota
  • HƯỚNG DẪN HỌC TẬP

  • View detail >>
    You have completed 0% of the course
  • HƯỚNG DẪN SINH VIÊN ĐĂNG NHẬP HỆ THỐNG
    • Hướng dẫn đăng nhập
    • Hướng dẫn vào khóa học
  • Introduction
    • Welcome
  • Unit 1: Values
    • Introduction - Unit 1: Values
    • Get Started With Values
    • Play with Values
    • Playground Basics
    • Naming and Identifiers
    • Simulation
    • Strings
    • Constants and Variables
    • Word Games
    • Build a PhotoFrame App
    • Design for People
  • Episode 1: The TV Club
    • Introduction - Episode 1: The TV Club
    • Searching for Content
    • Sharing Personal Information
    • Ordering Online
    • Reflection: Episode 1
  • Unit 2: Algorithms
    • Introduction - Unit 2: Algorithms
    • Get Started with Algorithms
    • Play with Programs
    • Functions
    • Types
    • Parameters and Results
    • Making Decisions
    • BoogieBot
    • Data Visualization
    • Build a QuestionBot App
    • Design an Experience
  • Episode 2: The Viewing Party
    • Introduction - Episode 2: The Viewing Party
    • Accessing the Show
    • Streaming on the Network
    • Reflection: Episode 2
  • Unit 3: Organizing Data
    • Introduction - Unit 3: Organizing Data
    • Get Started with Organizing Data
    • Play with Complex Data
    • Instances, Methods, and Properties
    • Arrays and Loops
    • Structures
    • Enums and Switch
    • Testing Code
    • Processing Data
    • Pixel Art
    • Password Security
    • Visualization Revisited
    • Build a BouncyBall App
    • Design a Prototype
  • Episode 3: Sharing Photos
    • Introduction - Episode 3: Sharing Photos
    • Capturing Images
    • Posting on Social Media
    • Reflection: Episode 3
  • Unit 4: Building Apps
    • Introduction - Unit 4: Building Apps
    • Get Started with App Development
    • Play with App Components
    • Color Picker
    • ChatBot
    • Rock, Paper, Scissors
    • MemeMaker
    • Build an ElementQuiz App
    • Design for Impact
  • Appendix
    • Episode Technical Concepts
    • Glossary
Course overview
Assessment

Progress
Criteria name Weighting (%) Score Progress (%)
Unit 3: Organizing Data

Arrays and Loops

Unit 3: Organizing Data|Play

What you'll build

  • A vote counter that tallies whether a measure passes or fails.
  • A tracker that comments on your progress towards a daily goal.
  • A filter that seeks out messages that contain a certain word.

What you'll learn

  • How to group items together into a single collection.
  • How to perform functions on a whole collection of items at once.

Key vocabulary

  • Array
  • Index
  • Literal
  • Loop
  • for...in

Introduction

The power of programming lies in the fact that your work is reusable. If you wrote ​ a function that turned one photo into a black-and-white image, you could use it on all your photos just by calling it with the ​correct arguments.

That works great if you're transforming and storing each photo individually. But what if you wanted to process a collection of photos all at once? In this lesson, ​you’ll work on storing and transforming groups of items so you can reuse your work with even greater efficiency and power.

Go Build

Open the Arrays and Loops.playground file in your course resources and follow the instructions.

Screenshot of the ArraysAndLoops playground

Reflection Questions

Think of a couple collections you have in real life, whether photos, device cables, socks, or cousins.

What are actions you'd want to take on each item in the group? Make up some function names and write pseudocode to describe the actions. For example:

for friend in soccerFriends {
  greet(friend)
  invite(friend, toGame: "US-Mexico exposition game")
  sayGoodbyeTo(friend)
}

Think of an app you use that has collections of similar items, like photos, messages, video game characters, or something else entirely. Write down your guesses for what you think those collections might be named in the app's code, remembering to use camel case. Also write down your guess about what type of thing makes up those collections.

Summary

Arrays are important data abstractions. They help you work with large collections of items as groups without having to manage lots of separate variables. Collections of data such as arrays are what empower loops—and loops are an example of the core procedural abstraction of iteration.

You've looped over arrays by writing code that executes the same steps for every item in a collection, and you even created your own collections of numbers and strings. In the next lesson, you'll see how to make and use custom types that you design yourself.

Remember

Collections of data such as arrays are what empower loops.

Report error