Apply a callback to an array: Difference between revisions

no edit summary
No edit summary
Line 2,687:
Result:
<lang python>0 1 4 9 16 25 36 49 64 81</lang>
 
=={{header|QB64}}==
<lang QB64>
'Task
'Take a combined set of elements and apply a function to each element.
'UDT
Type Friend
Names As String * 8
Surnames As String * 8
Age As Integer
End Type
 
Dim Friends(1 To 6) As Friend
Restore
FillArray
SearchForAdult Friends(), LBound(friends), UBound(friends)
 
End
 
Data "John","Beoz",13,"Will","Strange",22
Data "Arthur","Boile",16,"Peter","Smith",21
Data "Tom","Parker",14,"Tim","Wesson",24
 
Sub FillArray
Shared Friends() As Friend
Dim indeX As Integer
For indeX = LBound(friends) To UBound(friends) Step 1
Read Friends(indeX).Names, Friends(indeX).Surnames, Friends(indeX).Age
Next
End Sub
 
Sub SearchForAdult (F() As Friend, Min As Integer, Max As Integer)
Dim Index As Integer
Print "Friends with more than 18 years old"
For Index = Min To Max Step 1
If F(Index).Age > 18 Then Print F(Index).Names; " "; F(Index).Surnames; " "; F(Index).Age
Next Index
End Sub
 
</lang>
 
=={{header|Quackery}}==