Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- while
- for
- Pipelining
- Class
- data structure
- computer
- instruction
- control
- php
- MacOS
- DoM
- architecture
- github
- DS
- Java
- html
- XML
- MIPS
- DATAPATH
- Linux
- web
- python
- system
- Algorithm
- javascript
- CSS
- mysql
- DB
- react
- function
Archives
- Today
- Total
YYYEJI
[JAVA] for문이란? 본문
728x90
for문이란?
for문은 어떠한 행위를 반복하면서, 반복되는 횟수를 제어하고 싶을 때 사용하며,
Counting loop 라고도 불립니다.
for(i = 0; i<n; i++){
Action code
}
public static void main(String[] args) {
String month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
for(int i = 0; i<month.length; i++) {
System.out.println(month[i]);
}
}
Array의 길이만큼 for문이 돌아가며, array의 내용을 하나씩 출력합니다.
이처럼 for문은 array와 함께 자주 사용됩니다.
여기서 알아두면 좋은 것이 있습니다.
for문에서 i = 0으로 초기화 시킬 때 콤마(,)를 통해 여러개의 변수를 초기화 시킬 수 있다는 점입니다.
public static void main(String[] args){
int i, product;
for(i = 1, product = 1; i<10; i++) {
product = product * i;
}
System.out.println("Product: " + product);
}
◡̈
'Java' 카테고리의 다른 글
[JAVA] While문이란? (0) | 2022.12.24 |
---|---|
[JAVA] For-each문이란? (0) | 2022.12.24 |
[JAVA] Switch 문이란? (0) | 2022.12.24 |
[JAVA] 조건부 연산자(Conditional operator) (0) | 2022.12.24 |
[JAVA] If 문이란? (0) | 2022.12.24 |