Tag: loop
For Each loop in Java
Java 5 brought in the support in the support for foreach loop that lets the developers to iterate over collections pretty easily. The syntax for the foreach loop in java looks like the one shown below. for (<datatype> item: collection) { // Process the item } For Each loop in Java Below is an example that demonstrates foreach loop in java. package com.abundantcode; import java.util.ArrayList;…
Do-While Loop example in Java
The do-while loop in java is similar to the while loop except that the do-while loop is guaranteed to execute at least once . The do while loop evaluates its condition at the bottom of the loop. The syntax of the do-while loop in java can be written as do{statement(s)}while(expression) Do-While Loop example in Java Below is a sample code snippet demonstrating the usage of…
How to Skip Iteration of a foreach loop in C# ?
When using C# programming language , there are times when you might want to skip over the iteration based on some condition and jump over to the next iteration. How to Skip Iteration of a foreach loop in C# ? continue keyword comes to your rescue for this use case. When you want to skip the processing of current iteration and jump to the next…