Description: For Each item In array [ statements ] [ Exit For ] [ statements ] Next [ item ] Steps to Reproduce: cf. infra for new code snippet Actual Results: n/a Expected Results: n/a Reproducible: Always User Profile Reset: No Additional Info: Sub For_Each vector = Array(1,"deux",3.08, &hFFFFFFFF) For Each item In vector MsgBox item Next item End Sub Sub ExampleSort Dim sEntry(9) As String Dim iCount As Integer Dim iCount2 As Integer Dim sTemp As String sEntry = Array("Jerry", "Patty", "Kurt", "Thomas", "Michael", _ "David", "Cathy", "Susie", "Edward", "Christine") For iCount = 0 To 9 For iCount2 = iCount + 1 To 9 If sEntry(iCount) > sEntry(iCount2) Then sTemp = sEntry(iCount) sEntry(iCount) = sEntry(iCount2) sEntry(iCount2) = sTemp End If Next iCount2 Next iCount For iCount = 0 To 9 Step 1 Print sEntry(iCount) Next iCount End Sub
tip: A For...Next Statement works well when you can associate each iteration of a loop with a control variable and determine that variable's initial and final values. However, when you are dealing with a collection, the concept of initial and final values isn't meaningful, and you don't necessarily know how many elements the collection has. In this kind of case, a For Each...Next loop is often a better choice.
Moving to NEW
https://opengrok.libreoffice.org/xref/core/basic/source/comp/loops.cxx?r=7ddedd25#207 https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=f853ec31#2545 https://opengrok.libreoffice.org/xref/core/basic/source/runtime/runtime.cxx?r=f853ec31#2965
LibreOfficiant committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/1dd1b76bc1c6ca249bd2b3c605de642f0761072d tdf#128655 LibO Basic For loops variations It will be available in 6.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Mike Kaganski committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/232a423c88d3f4a30be9e7d6917f65cb9522191c Revert "tdf#128655 LibO Basic For loops variations" It will be available in 6.5.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Documentation has beeb provided