如何在一定迭代后打破树枝中的循环?

时间:2016-11-14 14:48:43

标签: twig symfony

我的twig文件中有以下代码

{% for item in items %}
    //iterate over each item
    //do your logical stuff
{% endfor %}

但仅仅因为我{{{{{}}}}项目的结构,我希望在1次迭代后打破它。

2 个答案:

答案 0 :(得分:1)

slice过滤器可用于此目的:

{% for item in items|slice(0, 1) %}
    //iterate over each item
    //do your logical stuff
{% endfor %}

答案 1 :(得分:1)

循环功能并没有真正突破。但是请通过设置标志来尝试:

Private Sub PostAssigned_AfterUpdate()

Dim strCriteria As String
Dim varItem As Variant
Dim intCounter As Integer
Dim strClear, strUpdate As String
Dim LArray() As String

For Each varItem In Me![PostAssigned].Value
  strCriteria = strCriteria & varItem & ","
Next

LArray = Split(strCriteria, ",")

DoCmd.SetWarnings False

strClear = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = 0 WHERE (((MasterGeneralData.DA_ID)= " & Me.DAAAID & "));"
DoCmd.RunSQL (strClear)

For i = LBound(LArray) To UBound(LArray)
strUpdate = "UPDATE MasterGeneralData SET MasterGeneralData.DA_ID = " & Me.DAAAID & " WHERE (((MasterGeneralData.Emp_Design)= '" & LArray(i) & "'));"
DoCmd.RunSQL (strUpdate)
Next i

DoCmd.SetWarnings True

MsgBox "Dealing Assistant details Updated successfully "

End Sub