Monday, April 10, 2006

The Parallelism Bug

Introduction

The computer can process one and only one statement at a time, and no more. The "parallelism bug" is the thought that the computer knows about and can process several statements at the same time, somehow in parallel (Pea 1986). Of course, several lines of code can't be active or known by the computer at the same time.

Program

public class Main {    
    public static void main(String[] args) {
        int size = 0;
        for (size = 1; size <= 10; size++) System.out.println(size);
        System.exit(0); // terminate program
        if (size == 10) System.out.println("Hello");
    }
}

According to Pea (1986) students think that when size is equal to ten in the for loop, "Hello" is printed. Of course, in this program, the if (size == 10) System.out.println("Hello"); statement will never be reached.

References

No comments: