A transform stage computes a new value for each input item.

Program

Play the program to subtract the selected discount from each price.

discount
transform_prices.dart
Replay: real traced execution (multi-file project)
void main() {
  var prices = [10, 25, 40];
  var discount = 5;
  var net = <int>[];
  for (var price in prices) {
    net.add(price - discount);
  }
  print('net=${net.join(",")}');
}
void main() {
  var prices = [10, 25, 40];
  var discount = 10;
  var net = <int>[];
  for (var price in prices) {
    net.add(price - discount);
  }
  print('net=${net.join(",")}');
}
  1. prices ← [10, 25, 40]

    1void main() {2  var prices = [10, 25, 40];3  var discount = 5;
    values this step[10, 25, 40]prices
  2. discount ← 5

    2var prices = [10, 25, 40];3var discount = 5;4var net = <int>[];
    values this step5discount
  3. net ← []

    3var discount = 5;4var net = <int>[];5for (var price in prices) {
    values this step[]net
  4. price ← 10

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step10price
  5. net ← [5]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[5]net10price5discount
  6. price ← 25

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step25price
  7. net ← [5, 20]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[5, 20]net25price5discount
  8. price ← 40

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step40price
  9. net ← [5, 20, 35]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[5, 20, 35]net40price5discount
  10. print('net=${net.join(",")}');

    7  }8  print('net=${net.join(",")}');9}
    outputnet=5,20,35
    values this step[5, 20, 35]net
  1. prices ← [10, 25, 40]

    1void main() {2  var prices = [10, 25, 40];3  var discount = 10;
    values this step[10, 25, 40]prices
  2. discount ← 10

    2var prices = [10, 25, 40];3var discount = 10;4var net = <int>[];
    values this step10discount
  3. net ← []

    3var discount = 10;4var net = <int>[];5for (var price in prices) {
    values this step[]net
  4. price ← 10

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step10price
  5. net ← [0]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[0]net10price10discount
  6. price ← 25

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step25price
  7. net ← [0, 15]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[0, 15]net25price10discount
  8. price ← 40

    4var net = <int>[];5for (var price in prices) {6  net.add(price - discount);
    values this step40price
  9. net ← [0, 15, 30]

    5for (var price in prices) {6  net.add(price - discount);7}
    values this step[0, 15, 30]net40price10discount
  10. print('net=${net.join(",")}');

    7  }8  print('net=${net.join(",")}');9}
    outputnet=0,15,30
    values this step[0, 15, 30]net
list `[10, 25, 40]` creates an ordered list.
transform `price - discount` computes one output per input.
typed list `<int>[]` creates an empty integer list.