본문 바로가기
Programming/Java

6 for loop (feat. Nested, foreach)

by Dowon Kang 2024. 1. 7.

1. for Loop

The for loop in Java is a control flow statement that allows you to repeatedly execute a block of code as long as a certain condition is true.

 

 


 

2. Nested for Loop

A nested for loop is a for loop inside another for loop. 

 

Example 1 - 구구단 

 

Example 2 

This is often used when you need to iterate over a two-dimensional array.

 

 


 

 

3. Enhanced for Loop (foreach Loop)

The enhanced for loop, also known as the foreach loop, provides a simpler way to iterate over elements in an array or a collection. 

It eliminates the need for explicit indexing and makes the code more readable. 

 

'Programming > Java' 카테고리의 다른 글

8 Array (배열)  (0) 2024.01.19
7 while loop (feat. do-while)  (0) 2024.01.07
5 If & Switch (feat. break, continue)  (0) 2024.01.07
4 Operation (연산)  (1) 2023.12.30
3 Casting  (0) 2023.12.29

댓글