// ForEach Example
var School;
School = new Array("Principal", "Mr. Garrison", "Chef");
School.forEach(listItem)
function listItem(item){
NSB.Print(item);
}
ForEach: Difference between revisions
Jump to navigation
Jump to search
Created page with "ForEach(''object'', ''function'' == Description == ForEach calls a function on each member of an objects. Object can be arrays, collections, objects, classes or controls...." |
|||
(10 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
ForEach('' | ForEach(''array'', ''function'') | ||
== Description == | == Description == | ||
ForEach calls | ForEach calls ''function'' on each element of ''array''. | ||
The BASIC implementation of this function is consistent with [https://documentation.help/MS-Office-VBScript/vsstmForEach.htm VBScript]: ''element'' is a simple variable which gets the value of each element in the ''array'' sucessively. | |||
If you're using JavaScript, the [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach JavaScript specification] is fully supported. | |||
== Example == | |||
<tabber> | |||
< | JavaScript= | ||
<syntaxhighlight lang="JavaScript"> | |||
// ForEach Example | // ForEach Example | ||
Line 28: | Line 22: | ||
function listItem(item){ | function listItem(item){ | ||
NSB.Print(item); | NSB.Print(item); | ||
} | }</syntaxhighlight> | ||
</ | |-| | ||
BASIC= | |||
<syntaxhighlight lang="vb.net"> | |||
Rem ForEach Example | |||
Dim School | |||
School = Array("Principal", "Mr. Garrison", "Chef") | |||
ForEach(School, listItem) | |||
Function listItem(item) | |||
Print item | |||
Next</syntaxhighlight> | |||
</tabber> | |||
== Output == | == Output == | ||
Line 41: | Line 46: | ||
== Related Items == | == Related Items == | ||
[[do...loop|Do...Loop]], [[exit|Exit]], [[for...next|For...Next]], [[while...wend|While...Wend]] | [[do...loop|Do...Loop]], [[exit|Exit]], [[for...next|For...Next]], [[while...wend|While...Wend]], [[For Each...Next]] | ||
[[Category:Language Reference]] | [[Category:Language Reference]] | ||
[[Category:Statements - Flow of control]] | [[Category:Statements - Flow of control]] | ||
[[Category:BASIC Functions]] |
Latest revision as of 12:51, 4 August 2024
ForEach(array, function)
Description
ForEach calls function on each element of array.
The BASIC implementation of this function is consistent with VBScript: element is a simple variable which gets the value of each element in the array sucessively.
If you're using JavaScript, the JavaScript specification is fully supported.
Example
Rem ForEach Example
Dim School
School = Array("Principal", "Mr. Garrison", "Chef")
ForEach(School, listItem)
Function listItem(item)
Print item
Next
Output
Principal Mr. Garrison Chef