learning-journal

102-Learning journal

This project is maintained by cmboell

Operators and Loops

Chapter 4: Decisions & Loops (pages 150,151,156,157)

You can evaluate a situation by comparing one value in the script to what you expect it might be. The result will be a Boolean: true or false. Comparison operator examples:

Comparison operators usually return single values of true or false. Logical operators allow you to compare the results of more than one comparison operator. Logical operator examples:

Logical expressions are evaluated left to right. If the first condition can provide enough information to get the answer, then there is no need to evaluate the second condition. If the first condition is false the entire expression is false.

Chapter 4 (pages 170-173, 176)

Loops check a condition. If it returns true, a code block will run. Then the condition will be checked again and if it still returns true, the code block will run again. It repeats until the condition returns false.

There are 3 common types of loops:

A for loop uses a counter as a condition. This instructs the code to run a specified number of times. The condition is made up of 3 statements: