Unable to use If condition in For each Rec loop

Unable to use If condition in For each Rec loop

Hi,

I am facing following problem while inserting records in a table. If I give any if condition in " for each rec in R " loop,
I get an error. If I do not give any if condition then the loop works fine.

Is it now allowed to give an If condition with For each Record loop. Pls clarify 

for each rec in R
{
        if (rec.Dep_Method== "Straight Line")
            {   
                D_Amt = (rec.Pur_Value - rec.ESal_Value)/rec.Exp_Life;
            }
    insert into Depreciation_Details
    [
        FYear_Start = input.Fin_Yr_Start.toLong()
        FYear_End = input.Fin_Yr_End
        Ass_Cat = rec.Asset_Category
        Ass_SCat = rec.Asset_Sub_Category
        Ass_ID = rec.Ass_ID
        Ass_Master_ID = rec.ID
        Dep_Amt =D_Amt
        OBook_Value = rec.Book_Value
        Added_User = zoho.loginuser
    ]
}

Thanks,

Milind Manohar