Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Add for each loop in loops.md in java tutorial #75

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion java/control-statements/loops.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,30 @@ public class DoWhileExample {
}
```

#### Check result [here](https://onecompiler.com/java/3vk6cdxsu)
#### Check result [here](https://onecompiler.com/java/3vk6cdxsu)

## For Each

For each loop is used exclusively to loop through elements in an array. Usually for each loop is preferred when you want just values only in less amount of code.

### Syntax

```java
for (type variableName : arrayName) {
// code
}
```
### Example

```java
public class ForExample {
public static void main(String[] args) {
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
for (String car : cars) {
System.out.println(car);
}
}
}
```

#### Check Result [here](https://onecompiler.com/java/42mma34yh)