I spent today coding and learning about loops. While loop, do while loop, for loop. I’m all looped out. Of course, I had to start my day by failing Tommy. He told me I should journal about it. But I can’t cause the reason for such failure in jest, which cannot be talked about here. So, I will leave that there and be vague about it.
I can’t drive my Bug. It needs brakes since they have gotten pretty low. I hope to get them done soon. I’ve called a place, but they don’t do European cars. Another place wants cash. I guess I need to call around.
It will be difficult to journal when I’m on the cruise. I wonder if I should bring my laptop.
Karissa will be 23 soon. On the 24th, to be exact. It’s hard to believe. Her sister and herself share the same day for their birthday. She had a normal birth. Though a few days later, they found a few holes in her heart. She was three months old when they decided they had to go along with the surgery. It was a bit of a rush to get her in surgery. Kevin and I had a day to talk to the insurance company to approve the surgery. The doctor said we couldn’t wait for her to gain more weight cause she wasn’t thriving. She was born at 7 lbs; three months later, she was only 8 lbs. But, after her surgery, she gained four pounds in one month! She had to have physical therapy after her surgery. I didn’t even know that babies had physical therapy. She hated it too. I didn’t know the severity of her hearing loss until she was 6. It was heartbreaking to learn that she was deaf in her left ear and had a severe loss in her right ear. But it never really bothered her much. I remember her as a two-year-old who loved giving us slug bugs. She always has a smile on her face. Though I still see her as my little girl, she has become a beautiful young lady.
JavaScript notes:
—————————————————
You can run the same code multiple times by using a loop. The while loop:
const ourArray = []; let i = 0; while (i < 5) { ourArray.push(i); i++; }
You can run the same code multiple times by using a loop.
The most common type of JavaScript loop is called a for loop because it runs for a specific number of times.
For loops are declared with three optional expressions separated by semicolons:
for (a; b; c), where a is the initialization statement, b is the condition statement, and c is the final expression.
The initialization statement is executed one time only before the loop starts. It is typically used to define and setup your loop variable.
The condition statement is evaluated at the beginning of every loop iteration and will continue as long as it evaluates to true. When the condition is false at the start of the iteration, the loop will stop executing. This means if the condition starts as false, your loop will never execute.
The final expression is executed at the end of each loop iteration, prior to the next condition check and is usually used to increment or decrement your loop counter.
In the following example we initialize with i = 0 and iterate while our condition i < 5 is true. We'll increment i by 1 in each loop iteration with i++ as our final expression.
const ourArray = []; for (let i = 0; i < 5; i++) { ourArray.push(i); }
For loops don't have to iterate one at a time. By changing our final-expression, we can count by even numbers.
We'll start at i = 0 and loop while i < 10. We'll increment i by 2 each loop with i += 2.
const ourArray = []; for (let i = 0; i < 10; i += 2) { ourArray.push(i); }
ourArray will now contain [0, 2, 4, 6, 8]. Let's change our initialization so we can count by odd numbers.
A for loop can also count backwards, so long as we can define the right conditions.
In order to decrement by two each iteration, we'll need to change our initialization, condition, and final expression.
We'll start at i = 10 and loop while i > 0. We'll decrement i by 2 each loop with i -= 2.
const ourArray = []; for (let i = 10; i > 0; i -= 2) { ourArray.push(i); }
ourArray will now contain [10, 8, 6, 4, 2]. Let's change our initialization and final expression so we can count backwards by twos to create an array of descending odd numbers.