App Programming/JavaScript

[JavaScript] do-while 루프

goatlab 2023. 6. 1. 09:25
728x90
반응형
SMALL

do-while 루프

 

do-while 문은 테스트 조건이 거짓으로 평가될 때까지 지정된 구문을 실행하는 루프를 만든다.

 

html

 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
    </head>
    <body>
        <script type="text/javascript" src="default.js"></script>
    </body>
</html>

 

js

 

var i = 1

do {
document.write("dowhile" + "<br>")
i++
} while (i <= 10)
document.write("End of do while loop" + "<br>")

// 1부터 100까지의 합계 구하기
var sum = 0
var x = 1

do {
sum = sum + x
x++
} while (x <= 100)
document.write(sum)

728x90
반응형
LIST