# Control Flow

## Objectives

* Describe the benefits of altering control flow in JavaScript
* Use boolean statements to return true and false values
* Utilize if/else statements in order to skip blocks of code
* Identify truthy and falsey values
* Utilize for, for...in, and while loops to loop through data structures and repeat code

## Control Flow

Control flow is the order in which the computer executes statements in a script. Javascript executes top-to-bottom, *unless we alter the control flow*.

**Why/how would we alter the control flow?** 1. Skip lines of code based on a condition. 2. Repeat lines of code when traversing a data set or just for the sake of DRY code.

**What kinds of statements do you remember from the prework that changed control flow?**

**Here are some statements we can use to alter the control flow:** 1. [if](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) 2. [switch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) 3. [while](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while) 4. [for](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for) 5. [for...in](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in)

But before that, let's create the expressions needed for these statements.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://romebell.gitbook.io/sei-802/javascript/js-control-flow.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
