Page under construction!!

Sequence of integers

Consider the following program sequence_int_bug.go (sequenza_interi_bug.go) that is bugged. The program reads a sequence of integers from standard input. The reading stops when the input number is less than the previously read number. The program prints the length of the non-decreasing sequence read.

package main

import "fmt"

func main() {
    var previous, current int

    count := 0
    for previous <= current {
        fmt.Scan(&previous)
        fmt.Scan(&current)
        count ++
        previous = current
    }
    fmt.Println("Number of valid values:", count)
}

Analyze the program’s requirements specification and answer the following questions.

  1. When must the program stop reading data?

  2. Must the program store the input data in single variables or in structures (array, slice, etc.)?

  3. How many and which data must be kept in memory simultaneously for processing?

  4. Which aspects are not correctly handled by the program?

  5. Now write a program sequence_int.go that meets the requirements specification e produces the correct output.