CONDITIONALS Flashcards

1
Q

What is a statement?

A

A statement is a set of instructions in the form of a code block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the control flow?

A

Control flow is the order in which the code is executed when a program is running. Typically, code in a program runs sequentially from top to bottom, starting with the first line of code and ending with the last one.

We can change the control flow of a program using conditional statements, loops, or function calls. In this lesson, we’ll learn how you can alter the program’s control flow using conditional statements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are conditional statements?

A

Conditional statements (or conditionals) are blocks of code containing instructions that will be executed if a certain condition is met.

Conditional statements are created using the if, else and else if blocks or using the switch statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the if statement ?

A

The if statement (or conditional block) executes a block of instructions if a specified condition is true. The condition is an expression that evaluates to true or false.

If the condition inside of the parenthesis evaluates to true, the code block inside of the curly braces {} will run.

Conditional statements are commonly used in combination with comparison operators (e.g., >, <, >=, <=, ===, etc.) or logical operators (&&, ||, !).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the else statement?

A

The else statement is executed when the previous if/else if statement conditions are false.

Sometimes we may need to create multiple conditions. When dealing with multiple conditions, we want one thing to happen if the condition is true and something else to happen if it is false.

In JavaScript, we can specify an alternative condition by adding an else statement to the end of the if/else if block.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the else if statements ?

A

The if / else statement allows us to specify two options: the main condition and an alternative condition. You often may need to specify more than two or more conditions. The else if block allows you to do exactly that.

To be able to chain multiple conditions, we use else if statements.

The else if statement is executed when the previous if or else if statement condition is false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the important syntax rules to follow for if, else if and else?

A

A couple of important syntax rules to follow when writing if, else if and else statements:

if and else if statements always require a condition in order to work,
else statements do not need a condition, as it means to run the block of code in every other possible case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the switch statement?

A

The switch statement is an alternative to the if/else/else if blocks.

We saw that if, else if and else statements can be combined to create complex conditional statements. However, combining multiple conditional statements at a time may result in a code that is hard to understand.

The swhich statement is an alternative to the if/else/else if blocks. It is used to simplify the if/else/else if conditional statements that have too many conditions.

The switch statement evaluates the provided expression, compares the expression’s value to a case value. It then executes the instruction block of the matching case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does evaluate the switch statement?

A

The switch statement evaluates the provided expression, compares the expression’s value to a case value. It then executes the instruction block of the matching case.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the break statement?

A

The break statement interrupts a block execution (in switch blocks and loop blocks) and continues with the execution of the program.

As you may have noticed, break statements are necessary for switch blocks. But you may ask, why is the break statement required when using switch?

If we forget to include a break statement in a case block the code execution will continue even after the correct case is matched. As a result, this will cause the following case blocks to execute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly