代码中的不可见语法错误

时间:2014-12-20 23:53:17

标签: ruby syntax

我一直在第23,28行和程序结束时遇到语法错误 在第23行,它说elsif声明是意料之外的,并不属于那里 在第28行,它表示不需要结束语句 在我的程序结束时,它说我错过了一个结束语

我不认为我有任何语法错误,所以如果有人可以帮助我发现我的错误,我会非常感激 谢谢:D

def get_last_date(strt,usage_list)
    if usage_list.empty?
        return "chemical left over"
    end

    date_list=[]
    for occurrence in usage_list
        if occurrence[0] != 0
            date_list+=[occurrence[2]]
        end
    end

    currdate=datelist.min                                       # this gets the earliest start date out of all the recurring uses
    lastuse=currdate

    while true                                                  # this loop is a loop for each day and each iteration icrements the currentdate by 1
        y=0
        usinglist=[]
        for recursion in usage_list                             # gets the recurring uses that have end_dates that are after the currdate and start_dates before the currdate
            if (recursion.length==4) &(recursion[3]< currdate)  # deletes a recurring use from the list of recurring uses if its past its end_date
                usage_list.delete_at(y)
                y--
        ****line 23**** elsif recursion[2] >= currdate
                usinglist+=[recursion]
            end

            y++
    *****line 28**** end

        used=false
        if usinglist.empty?
            return "chemical left over"
        end

        for uses in usinglist
            if uses[1]==0                                       # if its a daily periodicity subtract the amount from the total
                strt=strt-uses[0]
                used=true
            elsif uses[1]==currdate.cwday                       # if the periodicity day matches the current workday then subtracts the amount for weeky periodicity cases
                strt=strt-uses[0]
                used=true
            end
        end

        if strt==0                                              # if the chemical has been used up return either currdate or last use date appropriately
            return currdate
        elsif strt<0
            return lastuse
        end

        if used                                                 # sets the last used date to the current date if you used some of the chemical today
            lastuse=currdate
        end
        currdate=currdate+1                                     # increment currdate DateTime object
    end
end

1 个答案:

答案 0 :(得分:4)

y--
y++

这些陈述不存在于Ruby中。将它们更改为

y -= 1
y += 1

分别

此外,您似乎在第20行使用&而不是&&