namespace; include rt; // a loop for (i = 0; i < n; i++) with an int bound n the body leaves alone: // the check of t[i] against t's length is worked out once at the loop entry // (0 <= i and n <= length) and runs on each access only when that failed. so // a loop that stays inside skips it, and one that runs past the end still // faults at the same access, after the same side effects (the puts before it). int[8] t; int sweep(int n) { int i, s = 0; for (i = 0; i < n; i++) { t[i] = i; s = s + t[i]; } return s; } int from(int lo, int n) { int i, s = 0; for (i = lo; i < n; i++) s = s + t[i]; return s; } int main() { rt.put_n(sweep(8)); rt.put_c(10); rt.put_n(sweep(3)); rt.put_c(10); rt.put_n(from(2, 8)); rt.put_c(10); int i, n = 10; for (i = 0; i < n; i++) { rt.put_n(i); rt.put_c(32); t[i] = i; } rt.put_s("not reached\n"); return 0; }