Introduction
Announcements

Schedule
Labs
Assignments
TA office hours

Tests, exam

Topic videos
Some course notes
Extra problems
Lecture recordings

Discussion board

Grades so far

4. Write a 'while' loop in sh to add the squares of the integers from 20 to 50, inclusive, and output the total.

Solution:

sum=0
n=20
while test $n -le 50
do
    squ=`expr $n \* $n`
    sum=`expr $sum + $squ`
    n=`expr $n + 1`
done
echo $sum


[sample midterm from Winter 2011]