blob: 0b3f476e7e6f7856ca8096ff6b2c99efe1135a29 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
namespace;
include rt;
// a fixed array T[n] with a variable index is checked against n. a loop whose
// test is the constant n proves the index and drops the check; a constant
// index is checked when it is compiled.
int main() {
int[6] t; int i, s = 0, k = 6;
for (i = 0; i < 6; i++) t[i] = i * i;
for (i = 0; i < 6; i++) s = s + t[i];
rt.put_n(s); rt.put_c(10);
i = 2; rt.put_n(t[i] + t[5]); rt.put_c(10);
i = 0;
while (i <= k) { s = t[i]; i++; }
rt.put_s("not reached\n");
return 0;
}
|