Search⌘ K
AI Features

Solution: Smart Greenhouse Monitor

Explore how to use Dart's flow control statements including for-in loops, if-else conditions, and else blocks to create a smart greenhouse monitor that activates heating or signals optimal temperature based on daily readings.

We'll cover the following...
Dart
void main() {
final dailyTemperatures = [12, 22, 18, 35, 14, 28];
for (final temp in dailyTemperatures) {
if (temp < 15) {
print('Heater activated.');
} else if (temp > 30) {
print('Cooler activated.');
} else {
print('Optimal.');
}
}
}

Solution explanation

In the main.dart file:

    ...