"For 루프"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 하나는 보이지 않습니다)
7번째 줄: 7번째 줄:
{{참고|Bash for}}
{{참고|Bash for}}
[[분류:Bash]]
[[분류:Bash]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
for (( i = 1; i < 4; i++ )); do
for (( i = 1; i < 4; i++ )); do
echo "i = $i"
echo "i = $i"
14번째 줄: 14번째 줄:
# i = 2
# i = 2
# i = 3
# i = 3
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
for i in $(seq 1 3); do
for i in $(seq 1 3); do
echo "i = $i"
echo "i = $i"
done
done
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
for i in `seq 1 3`; do
for i in `seq 1 3`; do
echo "i = $i"
echo "i = $i"
done
done
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
for i in {1..3}; do
for i in {1..3}; do
echo "i = $i"
echo "i = $i"
done
done
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
i=1
i=1
while [ $i -lt 4 ]; do
while [ $i -lt 4 ]; do
36번째 줄: 36번째 줄:
i=`expr $i + 1`
i=`expr $i + 1`
done
done
</source>
</syntaxhighlight>
<source lang='bash'>
<syntaxhighlight lang='bash'>
for i in 2 3 5; do
for i in 2 3 5; do
echo "i = $i"
echo "i = $i"
44번째 줄: 44번째 줄:
# i = 3
# i = 3
# i = 5
# i = 5
</source>
</syntaxhighlight>


==C==
==C==
[[분류:C]]
[[분류:C]]
<source lang='c'>
<syntaxhighlight lang='c'>
for(int i=1; i<=10; i++) {
for(int i=1; i<=10; i++) {
sum += i;
sum += i;
}
}
</source>
</syntaxhighlight>


==CMD==
==CMD==
[[분류:Cmd]]
[[분류:Cmd]]
<source lang='bash'>
<syntaxhighlight lang='bash'>
(@echo off & for /L %i in (1,1,4) do echo i = %i) & echo on
(@echo off & for /L %i in (1,1,4) do echo i = %i) & echo on
REM i = 1
REM i = 1
62번째 줄: 62번째 줄:
REM i = 3
REM i = 3
REM i = 4
REM i = 4
</source>
</syntaxhighlight>


==Java==
==Java==
[[분류:Java]]
[[분류:Java]]
<source lang='Java'>
<syntaxhighlight lang='Java'>
for(int i=1; i<=10; i++) {
for(int i=1; i<=10; i++) {
sum += i;
sum += i;
}
}
</source>
</syntaxhighlight>


==JavaScript==
==JavaScript==
[[분류:JavaScript]]
[[분류:JavaScript]]
<source lang='JavaScript'>
{{참고|자바스크립트 for}}
<syntaxhighlight lang='JavaScript'>
for(var i=1; i<=10; i++) {
for(var i=1; i<=10; i++) {
sum += i;
sum += i;
}
}
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[분류:PHP]]
[[분류:PHP]]
{{참고|PHP for}}
{{참고|PHP for}}
<source lang='php'>
<syntaxhighlight lang='php'>
$sum = 0;
$sum = 0;
for($i=1; $i<=10; $i++) {
for($i=1; $i<=10; $i++) {
89번째 줄: 90번째 줄:
}
}
echo $sum;
echo $sum;
</source>
</syntaxhighlight>


==Python==
==Python==
[[분류:Python]]
[[분류:Python]]
{{참고|파이썬 for}}
{{참고|파이썬 for}}
<source lang='Python'>
<syntaxhighlight lang='Python'>
sum = 0
sum = 0
for i in range(10):
for i in range(10):
sum += i
sum += i
print sum
print sum
</source>
</syntaxhighlight>


==Perl==
==Perl==
[[category: Perl]]
[[category: Perl]]
{{참고|펄 for}}
{{참고|펄 for}}
<source lang='Perl'>
<syntaxhighlight lang='Perl'>
my $sum = 0;
my $sum = 0;
for $i (1..4) {
for $i (1..4) {
111번째 줄: 112번째 줄:
printf("$sum\n");
printf("$sum\n");
# 10
# 10
</source>
</syntaxhighlight>


==Ruby==
==Ruby==
[[분류:Ruby]]
[[분류:Ruby]]
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
sum = 0
sum = 0
for i in 1..4
for i in 1..4
122번째 줄: 123번째 줄:
puts sum
puts sum
# 10
# 10
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
sum = 0
sum = 0
for i in 1...5
for i in 1...5
130번째 줄: 131번째 줄:
puts sum
puts sum
# 10
# 10
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
sum = 0
sum = 0
(1..4).each { |i| sum += i }
(1..4).each { |i| sum += i }
puts sum
puts sum
# 10
# 10
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
sum = 0
sum = 0
(1..4).each do |i|
(1..4).each do |i|
144번째 줄: 145번째 줄:
puts sum
puts sum
# 10
# 10
</source>
</syntaxhighlight>
<source lang='Ruby'>
<syntaxhighlight lang='Ruby'>
sum = 0
sum = 0
[1, 2, 3, 4].each { |i| sum += i }
[1, 2, 3, 4].each { |i| sum += i }
puts sum
puts sum
# 10
# 10
</source>
</syntaxhighlight>


==Visual Basic==
==Visual Basic==
[[분류:VB]]
[[분류:VB]]
<source lang='vb'>
<syntaxhighlight lang='vb'>
FOR I = 1 TO 10
FOR I = 1 TO 10
SUM = SUM + I
SUM = SUM + I
NEXT I
NEXT I
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==

2020년 11월 2일 (월) 02:31 기준 최신판

  다른 뜻에 대해서는 포문 문서를 참조하십시오.
for
for문

1 Bash[ | ]

for (( i = 1; i < 4; i++ )); do
	echo "i = $i"
done
# i = 1
# i = 2
# i = 3
for i in $(seq 1 3); do
	echo "i = $i"
done
for i in `seq 1 3`; do
	echo "i = $i"
done
for i in {1..3}; do
	echo "i = $i"
done
i=1
while [ $i -lt 4 ]; do
	echo "i = $i"
	i=`expr $i + 1`
done
for i in 2 3 5; do
	echo "i = $i"
done
# i = 2
# i = 3
# i = 5

2 C[ | ]

for(int i=1; i<=10; i++) {
	sum += i;
}

3 CMD[ | ]

(@echo off & for /L %i in (1,1,4) do echo i = %i) & echo on
REM i = 1
REM i = 2
REM i = 3
REM i = 4

4 Java[ | ]

for(int i=1; i<=10; i++) {
	sum += i;
}

5 JavaScript[ | ]

for(var i=1; i<=10; i++) {
	sum += i;
}

6 PHP[ | ]

$sum = 0;
for($i=1; $i<=10; $i++) {
	$sum += $i;
}
echo $sum;

7 Python[ | ]

sum = 0
for i in range(10):
	sum += i
print sum

8 Perl[ | ]

my $sum = 0;
for $i (1..4) {
	$sum += $i;
}
printf("$sum\n");
# 10

9 Ruby[ | ]

sum = 0
for i in 1..4
	sum += i
end
puts sum
# 10
sum = 0
for i in 1...5
	sum += i
end
puts sum
# 10
sum = 0
(1..4).each { |i| sum += i }
puts sum
# 10
sum = 0
(1..4).each do |i|
    sum += i
end
puts sum
# 10
sum = 0
[1, 2, 3, 4].each { |i| sum += i }
puts sum
# 10

10 Visual Basic[ | ]

FOR I = 1 TO 10
	SUM = SUM + I
NEXT I

11 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}