'BEGIN' 'COMMENT' This is a simple example of Jensen's device; 'COMMENT' This takes the sum of expr from lo to hi, inclusive. The variable index is incremented through the range.; 'REAL' 'PROCEDURE' SUM(LO, HI, INDEX, EXPR); 'VALUE' LO, HI; 'INTEGER' LO, HI, INDEX; 'REAL' EXPR; 'BEGIN' 'REAL' ACCUM; 'COMMENT' initialize accum to zero and add the terms.; ACCUM := 0.0; 'FOR' INDEX := LO 'STEP' 1 'UNTIL' HI 'DO' 'BEGIN' ACCUM := ACCUM + EXPR 'END'; SUM := ACCUM 'END'; 'BEGIN' 'COMMENT' Sum of integers, 1 to 20.; 'INTEGER' I; OUTREAL(1, SUM(1, 20, I, I)); OUTSTRING(1, "\n"); 'END'; 'BEGIN' 'COMMENT' sum of 10 die rolls; 'INTEGER' I; OUTREAL(1, SUM(1, 10, I, RAND 'MOD' 6)); OUTSTRING(1, "\n"); 'END'; 'BEGIN' 'comment; mean and variance; 'REAL' 'ARRAY' DATA[10]; 'INTEGER' I; 'REAL' MEAN, SUMD, SUMSQ; 'FOR' I:=1 'STEP' 1 'UNTIL' 10 'DO' READREAL(2, DATA[I]); SUMD = SUM(1, 10, I, DATA[I]); SUMSQ = SUM(1, 10, I, DATA[I]*DATA[I]); OUTSTRING(1, "Mean is: "); MEAN = SUMD / 10.0; OUTREAL(1, MEAN ); OUTSTRING(1, "Variance is :"); OUTREAL(1, SUMSQ / 10.0 - MEAN * MEAN); 'END' 'END'