While

while

1 Bash[ | ]

x=1
while [ $x -le 3 ]
do
  echo "x = $x"
  x=$(( $x + 1 ))
done
# x = 1
# x = 2
# x = 3
i=1
while [ $i -lt 4 ]
do
   echo "i = $i"
   i=`expr $i + 1`
done
# i = 1
# i = 2
# i = 3

2 PHP[ | ]

$x = 1;
while($x <= 5) {
  echo "[$x]";
  $x += 1;
}
  • alternative syntax
$x = 1;
while($x <= 5):
  echo "[$x]";
  $x += 1;
endwhile;

3 Python[ | ]

a = 1
sum = 0
while a <= 10:
	sum += a
	a += 1
print(sum)
# 55

4 Perl[ | ]

my $a = 1;
my $sum = 0;
while ($a <= 10) {
	$sum += $a;
	$a += 1;
}
print $sum;
# 55

5 Ruby[ | ]

i = 1
sum = 0
while i <= 10
	sum += i
	i += 1
end
puts sum
# 55
i = 1
sum = 0
while i <= 10 do
	sum += i
	i += 1
end
puts sum
# 55

6 같이 보기[ | ]

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