Mark As Completed Discussion

One Pager Cheat Sheet

  • By leveraging loops and iterations, we can automate the process of applying a similar operation to a collection of elements in a program.
  • Iteration and loops are programming structures that repeatedly execute a set of instructions, while iterables are objects, such as arrays and strings, that can be accessed one element at a time.
  • Loops are used to iterate over a collection of objects, with for and while loops being the most common types found in most programming languages, such as JavaScript.
  • In JavaScript, For loops are used to iterate over a sequence of elements by specifying three statements: a variable initiated before the loop starts, a boolean condition to be checked each time, and a value change to take place every time the code block is executed.
  • While loops are used to iterate over a sequence of elements, while a condition remains true, and they require initialization before the loop.
  • The loop will run while i is lesser than fruits.length, which is currently 6, because the last element was removed using fruits.pop().
  • The for loop syntax requires the comparison to compare the iterator variable with the array length, a number value, but the code uses the array numbers which will result in an error.
  • One must be aware of the break, continue, and infinite loop keywords when working with loops to ensure the program does not execute indefinitely.
  • The code will print all letters except for "o", skipping over it with continue and still printing p.
  • This program is an example of an infinite loop, since there is no code to change the value of a, and the loop condition of a <= 5 will always remain true.
  • Iterations (or loops) help us reduce lines of code, improve code reusability, and enable us to specify the number of times a code block needs to be repeated.