LinkedIn principal author Doug Winnie explains how to loop through values within an array. Using a for loop, you can repeat through all of the elements and stop the loop based on the array’s length function that stores the number of items in the array. The for each loop goes through all of the items in the loop and uses a single variable name to refer to each element without needing to know the array length.
- With a collection of values within an array,…it is common to want to repeat actions using a loop…across all the values within the array collection.…For instance, if I have a collection of values,…I might want to know what is the average of the values…within the array.…To do this, I need to create a loop.…The for loop is a good candidate to iterate…through all of the items in an array…because we have a set number of times we want to repeat.…An array has a function that stores how many values…are within the collection.…
So, for a group like this one,…it knows the array has 12 items.…We can use that as part of our for loop.…I'll start with an iterator.…I'll make sure the iterator is less than the number of items…in the array.…Since we start with zero, the twelfth element index…in the array is 11.…So, 11 is less than 12…which will work for the for loop and then,…when it gets to 12, the loop will end.…Now we can create a new value to store the sum…and then run through the loop.…
With each loop, we will take the specific value identified…
Author
Released
11/28/2016Join Doug Winnie as he explains the principles of programming and helps you connect to core concepts by exploring three ways that programmers perform their jobs. Doug starts by sharing the history of coding and then dives into functions, values, variables, and parameters used to define actions. He covers capturing input from users, creating conditional tests, using loops with arrays, and object-oriented programming basics. He also takes you beyond programming, into processes like debugging, refactoring, and building iteratively.
- Working with values and variables
- Breaking down tasks
- Customizing functions and parameters
- Building conditional tests
- Creating and changing arrays
- Working with objects and classes
- Debugging and refactoring code
- Going beyond the code as a programmer
Skill Level Beginner
Duration
Views
Related Courses
-
Introduction
-
Welcome1m 40s
-
What you should know1m 3s
-
-
1. Control Computers with Code
-
History of programming2m 9s
-
Forms of programming5m 12s
-
-
2. Define Actions Using Code
-
Break down tasks2m 29s
-
Variables and scope2m 9s
-
Return values from functions2m 15s
-
Work with an API1m 27s
-
3. Repeat Actions and Test for Conditions
-
Capture input from the user3m 31s
-
Create conditional tests4m 39s
-
Use while loops2m 11s
-
Use for loops3m 11s
-
Use loops with arrays2m 5s
-
-
4. Objects and OOP
-
Everything is an object2m 21s
-
Everything is a class4m 3s
-
Extend classes2m 7s
-
-
5. Beyond Programming
-
Debug problems2m 50s
-
-
Conclusion
-
Next steps1m 19s
-
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.
CancelTake notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.
Share this video
Embed this video
Video: Use loops with arrays