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

6번째 줄: 6번째 줄:
[[category: Bash]]
[[category: Bash]]
<source lang='bash'>
<source lang='bash'>
for i in 2 3 5
for i in {1..3}
do
do
  echo "i = $i"
  echo "i = $i"
done
done
# i = 1
# i = 2
# i = 2
# i = 3
# i = 3
# i = 5
</source>
</source>
<source lang='bash'>
<source lang='bash'>
for i in {1..3}
for (( c=1; c<4; c++ ))
do
do
   echo "i = $i"
   echo "i = $c"
done
done
# i = 1
# i = 1
24번째 줄: 24번째 줄:
</source>
</source>
<source lang='bash'>
<source lang='bash'>
for (( c=1; c<4; c++ ))
i=1
while [ $i -lt 4 ]
do
do
   echo "i = $c"
   echo "i = $i"
  i=`expr $i + 1`
done
done
# i = 1
# i = 1
32번째 줄: 34번째 줄:
# i = 3
# i = 3
</source>
</source>
<source lang='bash'>
<source lang='bash'>
for i in {1..5..2}
for i in 2 3 5
do
do
  echo "i = $i"
  echo "i = $i"
done
done
# i = 1
# i = 2
# i = 3
# i = 3
# i = 5
# i = 5
</source>
</source>
<source lang='bash'>
<source lang='bash'>
i=1
for i in {1..5..2}
while [ $i -lt 4 ]
do
do
   echo "i = $i"
   echo "i = $i"
  i=`expr $i + 1`
done
done
# i = 1
# i = 1
# i = 2
# i = 3
# i = 3
# i = 5
</source>
</source>



2013년 11월 21일 (목) 22:29 판

for
for문

1 Bash

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

2 C, Java

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 PHP

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

5 Visual Basic

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

6 같이 보기

7 참고 자료

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