입력한 값이 0 0
이면 반복문을 빠져나온다.
Bash
bash
while :; do
read a b
if [ "$a$b" == "00" ]; then
break
fi
echo $((a + b))
done
1
2
3
4
5
6
7
2
3
4
5
6
7
while :
== while true
== 무한루프
C
c
#include <stdio.h>
int main(void) {
int a, b;
while (1) {
scanf("%d %d", &a, &b);
if (a == 0 && b == 0) { break; }
printf("%d\n", a+b);
}
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Node.js
javascript
let list = require("fs").readFileSync(0).toString().trim().split("\n");
for (let l of list.slice(0,-1)) {
let [a, b] = l.split(" ").map(Number);
console.log(a+b);
}
1
2
3
4
5
2
3
4
5
PHP
php
<?php
while (1) {
fscanf(STDIN, "%d %d", $a, $b);
if ($a == 0 && $b == 0) { break; }
echo $a + $b."\n";
}
?>
1
2
3
4
5
6
7
2
3
4
5
6
7
Python3
python
while 1:
a, b = map(int, input().split())
if a==0 and b==0: break
print(a+b)
1
2
3
4
2
3
4
Ruby
ruby
while 1
a, b = gets.chomp.split().map {|i| i.to_i}
break if a==0 and b==0
puts a+b
end
1
2
3
4
5
2
3
4
5
Comments
Not supported comment edit and upvote
You can do it on this page if you want.