iStmt (SFor ident exp1 exp2 stm) = do iStmt (SSet ident exp1)
                                      cexp1 <- calcExp exp1
                                      cexp2 <- calcExp exp2
                                      doNTimes stm cexp1 (rangeExp cexp1 cexp2)
                                        where
                                          doNTimes stmt old 0 = return Null
                                          doNTimes stmt old times = do {
    next <- nextExp old;
    exp <- iStmt stmt;
    case exp of
    Null -> do iStmt (SSet ident next);
               doNTimes stmt next (times - 1)
    e -> return e
}
iStmt (SFor ident exp1 exp2 stm) = do iStmt (SSet ident exp1)
                                      cexp1 <- calcExp exp1
                                      cexp2 <- calcExp exp2
                                      doNTimes stm cexp1 (rangeExp cexp1 cexp2)
                                        where
                                          doNTimes stmt old 0 = return Null
                                          doNTimes stmt old times = do {
    next <- nextExp old;
    exp <- iStmt stmt;
    case exp of
    Null -> do iStmt (SSet ident next);
               doNTimes stmt next (times - 1)
    e -> return e
}
iStmt (SFor ident exp1 exp2 stm) = do iStmt (SSet ident exp1)
                                      cexp1 <- calcExp exp1
                                      cexp2 <- calcExp exp2
                                      doNTimes stm cexp1 (rangeExp cexp1 cexp2)
                                        where
                                          doNTimes stmt old 0 = return Null
                                          doNTimes stmt old times = do {
    next <- nextExp old;
    exp <- iStmt stmt;
    case exp of
    Null -> do iStmt (SSet ident next);
               doNTimes stmt next (times - 1)
    e -> return e
}