While

while

1 Bash[ | ]

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

2 PHP[ | ]

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

3 Python[ | ]

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

4 Perl[ | ]

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

5 Ruby[ | ]

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

6 같이 보기[ | ]