Search⌘ K
AI Features

Solution: Toxic Gas Leak Detection

Explore how to implement flow control in Dart using nested loops and conditional breaks to detect toxic gas leaks by evaluating sensor readings against a threshold. Understand how to manage loop execution and handle data safely with assertions for reliable detection logic.

We'll cover the following...
Dart
void main() {
final sensorGrid = [
[12, 45, 15],
[50, 105, 120],
[9, 14, 18],
[200, 15, 30]
];
assert(sensorGrid.isNotEmpty, 'Sensor grid data is missing.');
for (final sector in sensorGrid) {
for (final reading in sector) {
if (reading > 100) {
print('Evacuate sector! Leak level: $reading');
break;
}
}
}
}

Solution explanation

In the main.dart file:

  • ...