मुख्य कंटेंट तक स्किप करें
Trushi Jasani
EditReport

Control Statements

Control structures route program execution dynamically based on real-time runtime conditions.

1. The if...else if...else Statement Pattern

let engineSpeed: number = 75;

if (engineSpeed > 90) {
console.log("Critical velocity threshold reached!");
} else if (engineSpeed >= 50) {
console.log("Optimal operating efficiency.");
} else {
console.log("Sub-optimal velocity profile.");
}

2. The switch-case Construct

The switch block evaluates a single input statement expression against multiple strictly mapped case values:

enum StatusGate {
Pending,
Active,
Terminated
}

let pipelineStatus: StatusGate = StatusGate.Active;

switch (pipelineStatus) {
case StatusGate.Pending:
console.log("Queue buffering initialized.");
break;
case StatusGate.Active:
console.log("Pipeline clearing jobs.");
break;
case StatusGate.Terminated:
console.log("Flushing active memory traces.");
break;
default:
console.log("Unknown pipeline execution state.");
}

3. Inline Ternary Conditional Operations

For compact assignment mechanics, use the conditional ternary syntax:

let ageLimit: number = 21;
let registrationState: string = (ageLimit >= 18) ? "Authorized" : "Denied";
Finished reading? Mark this topic as complete.