YogeshChauhan . com

For Each Loop in Swift for Beginners

in Swift on May 3, 2020


It's an instance method that calls the given closure on each element in the sequence in the same order as a for-in loop.


func forEach(_ body: (Element) throws -> Void) rethrows

Where body =  A closure that takes an element of the sequence as a parameter.


let numberWords = ["one", "two", "three"]
numberWords.forEach { word in


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 How to Use SQL MAX() Function with Dates? #6 PHP Login System using PDO Part 1: Create User Registration Page

Recently Posted

Jun 16 What are Stored Procedures for SQL Server? Jun 16 What are Class Constants in PHP? Jun 15 A short basic guide on states in React Jun 15 How to define constants in PHP? Jun 15 How to define visibility for a property in PHP? Jun 15 How to use @if and @else in SCSS?

You might also like these

How to create a simple tab interaction using CSS?CSSWindow setInterval() Method in JavaScriptJavaScriptCreate dynamic selectors using SCSS (Sass)SCSSHow to add onclick event to html elements dynamically using JavaScript?JavaScriptHow to uninstall Cocoapods from the Mac OS?MiscHow to add multiple components in React app?ReactHow to scroll contents of HTML body horizontally and vertically using JavaScript?JavaScriptLearn to Make a Simple Contact Us Form using PHP and PDO-MySQLPHPDifferent Types of Functions in JavaScriptJavaScriptHow to Pop an Alert Box in PHP?JavaScriptWordPress: How to find all posts from a custom post type with specific custom field?WordPressWhat Is a Graph Database?Misc