Unit 6-lists, loops, and transversals Flashcards
list
an ordered collection of elements
element
an individual value in a list that is
assigned a unique index
index
a common method for referencing the elements in a list or string using numbers (lists in Javascript start with index 0
length
how many elements it contains, The length of the list is 1 more than the last index
How are lists an example of data abstraction?
They allow us to name and program with large collections of information while ignoring the low level details of how the data is stored, organized, etc.
what is a While Loop and how does it work?
uses a boolean condition to repeatedly run a block of code. If it is true it runs the block of code contained within it.
-This process of checking the condition and running the block of code is repeated as long as the Boolean condition remains true. -Once the Boolean expression becomes false it will stop.
for Loop
condenses the parts of a while loop into a shorter statement. Like the while loop, once the Boolean expression becomes false, the loop ends.
What are the three components of for and while loops?
Create a count/index variable
Ex. var count = 0
Write a while loop to check a condition
Ex. while (count <10)…
Increase/Decrease the value of count/index variable
Ex. …count ++
What is an iteration and what is an example?
Iteration (loops): a repetitive portion of an algorithm which repeats a specified number of times, while a condition is met, or until a given condition is no longer met
- an example is loops!
What is in an infinite loop and when do they occur?
occurs when the while condition is always true (or the ending condition will never occur); will result in cycling through a set of commands forever without stopping
When would you want to use a loop versus a function
Use a function when you have a piece of code (a procedure) that you might reuse in other places in your program.
Use a loop when there is something you need to do over and over again repeatedly (consecutively) or when you don’t want to call a function many times in a row manually.
Use a loop when you don’t want to call a function many times in a row manually
What is a simulation and why is it important?
Simulations are models of the real world that allow the user to investigate hypotheses and draw conclusions by inputting various sets of data or values to demonstrate the changing state of a phenomenon.
-Simulations allow us to test solutions or run experiments in a way that is usually cheaper, safer, and often times faster.
algorithm
finite set of instructions that accomplish a specific task.
what is the definition of a traversal?
the process of accessing each item in a list one at a time
how do lists relate to abstraction?
they manage complexity in programs by giving a collection of data a name without referencing the specific details of the representation.