Welcome. In this module, we will explore how computer programs make decisions. But first, let's briefly review the data structure we will be analyzing today: Arrays.
Click the cards below to reveal key concepts regarding Arrays.
To analyze the data inside an array, we need Conditional Statements. These allow the code to perform different actions based on different boolean (True/False) states.
| Condition Type | Syntax Structure | Best Use Case |
|---|---|---|
| If / Else | if (condition) { ... } else { ... } |
Binary decisions. Example: Is this password correct? Yes or No. |
| Else If | if... else if... else |
Checking multiple distinct conditions in sequence. Example: Is grade > 90? No. Is grade > 80? |
| Switch Statement | switch(val) { case x: ... break; } |
When a variable has specific, discrete values. Example: Menu selections (1=Open, 2=Save, 3=Exit). |
| Ternary Operator | (condition) ? trueVal : falseVal |
Short, one-line assignments. Example: status = (isOnline) ? "Connected" : "Offline" |
Scenario: You are analyzing an array of Network Packet Sizes. Normal traffic packets are usually small (< 50 bytes). Large packets (> 80 bytes) often indicate a data exfiltration attempt (a threat).
Task: Configure the firewall logic below to scan the array and flag the threats.