Structured Programming
Structured programming is a way of writing programs where you break a large problem into smaller parts. It uses three basic control structures: sequence, selection (if-else statements), and iteration (loops). JavaScript supports structured programming through its syntax and its control flow statements, and so do most other modern programming languages.
let sum = 0;
for (let i = 1; i <= 10; i++) {
if (i % 2 === 0) {
sum += i;
}
}
console.log(`The sum of even numbers from 1 to 10 is ${sum}`);
In this chapter, you will learn how structured programming works in JavaScript. That includes comparison operators and control structures such as if-else statements and loops.
Learning Outcomes
- Compare values using equality and comparison operators, and explain how type conversion affects the result
- Combine boolean expressions with logical operators, including short-circuit and truthy/falsy evaluation
- Control program flow with conditional statements, including if-else, ternary, and switch
- Write and apply loops to iterate over ranges, iterables, and object properties
- Apply structured programming concepts to solve practice problems