Notes

Conditionals

Control Flow : The order in which instructions are executed within a program.

Control Structures : Expressions that alter the control flow based on given parameters.

Conditional Statements : A control structure that is used to perform different actions based on different conditions.


Writing Conditional Statements


Mutually Exclusive Conditions

When to use If Statements

If we are working with a situation that is mutually exclusive, then we should use an If/Else Statement.

Age old principal for writing good code: DRY (Don’t repeat yourself)!


Basic Loops

Loops : Are a fundamental control structure that will repeatedly execute a section of code while a condition is true.

While Loops : Will execute a block of code as long a specified condition is true.

while (condition) {
  // code block to be executed
}

let index = 0;
while (index < 10) {
  console.log("The number is " + index);
  index++;
}

Important Loop Knowledge

For Loops For loops can be broken down into three sections:


for (<initital expression>;<condition>;<loopEnd expression>) {};

Translating From One Loop to Another

Here is an example of the same loop expressed as a while and for loop.


function forLoopDoubler (array) {
for (let i = 0; i < array.length; i++>) {
array[i] = array[i] \* 2
}
return array;
};

function forLoopDoubler (array) {
let i = 0;
while (i < array.length>) {
array[i] = array[i] \* 2;
i++;
}
return array;
};

Arrays

Using Arrays

Working with Arrays