Bug 128655 - Basic For statement supports "For Each item In array" second syntax that's not documented
Summary: Basic For statement supports "For Each item In array" second syntax that's no...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Documentation (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium trivial
Assignee: LibreOfficiant
URL:
Whiteboard: target:6.5.0
Keywords:
Depends on:
Blocks: Macro-StarBasic
  Show dependency treegraph
 
Reported: 2019-11-07 16:42 UTC by LibreOfficiant
Modified: 2020-09-03 07:35 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description LibreOfficiant 2019-11-07 16:42:03 UTC
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
Comment 1 LibreOfficiant 2019-11-07 16:44:14 UTC
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.
Comment 2 Xisco Faulí 2019-11-25 15:08:41 UTC
Moving to NEW
Comment 4 Commit Notification 2019-11-29 04:56:31 UTC
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.
Comment 5 Commit Notification 2019-11-29 06:09:23 UTC
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.
Comment 6 Alain Romedenne 2020-09-03 07:35:12 UTC
Documentation has beeb provided