์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ while ๋ฃจํ”„๋ฌธ์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

์šฐ์„  ๋ฌธ๋ฒ•๋ถ€ํ„ฐ ํ™•์ธํ•ด๋ณผ๊นŒ์š”??

 

 

while (์กฐ๊ฑด๋ฌธ){
   ์กฐ๊ฑด๋ฌธ์ด ์ฐธ์ธ๋™์•ˆ ์‹คํ–‰ํ•ด์•ผํ•  ๋ฌธ์žฅ
}

 

์ด์ œ ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ณผ๊นŒ์š”??
<script type="text/javascript">
<!--
var count = 0;
document.write("Starting Loop" + "<br />");
while (count < 10){
  document.write("Current Count : " + count + "<br />");
  count++;
}
document.write("Loop stopped!");
//-->
</script>

 

๊ฒฐ๊ณผ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋‚˜์˜ฌ๊ฒƒ ๊ฐ™๋‚˜์š”??

์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์™€์•ผ๊ฒ ์ฃ ??

 

Starting Loop
Current Count : 0
Current Count : 1
Current Count : 2
Current Count : 3
Current Count : 4
Current Count : 5
Current Count : 6
Current Count : 7
Current Count : 8
Current Count : 9
Loop stopped! 

 

 

 

 

์ž while๋ฌธ๊ณผ ๋น„์Šทํ•œ do-while๋ฌธ์„ ์•„์‹œ๋‚˜์š”? do-while๋ฌธ์€ ์ผ๋‹จ ๋จผ์ € ํ•œ๋ฒˆ ์‹คํ–‰์‹œํ‚จ ๋‹ค์Œ์— while๋ฌธ์„ ํƒ€๋Š”๊ฒ๋‹ˆ๋‹ค.

์—ญ์‹œ ๋ง๋ณด๋‹ค๋Š” ์‹ค์Šต์ด์ฃ ? 

 

๋ฌธ๋ฒ•๋ถ€ํ„ฐ ํ™•์ธํ•ด๋ณผ๊นŒ์š”??
do{
  ์ตœ์†Œ ํ•œ๋ฒˆ์€ ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ๋ฌธ์žฅ
} while (์กฐ๊ฑด๋ฌธ);

๊ทธ๋Ÿผ ์ด์ œ ์˜ˆ์ œ๋ฅผ ํ•œ๋ฒˆ ๋ด…์‹œ๋‹ค.
<script type="text/javascript">
<!--
var count = 0;
document.write("Starting Loop" + "<br />");
do{
  document.write("Current Count : " + count + "<br />");
  count++;
}while (count < 0);
document.write("Loop stopped!");
//-->
</script>

 

๊ฒฐ๊ณผ๊ฐ€ ์˜ˆ์ƒ์ด ๋˜๋‚˜์š”?

์•„๋ž˜์ฒ˜๋Ÿผ ๊ฒฐ๊ณผ๋ฅผ ์˜ˆ์ƒํ•˜์…จ๋‹ค๋ฉด ๋‹น์€์€ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ์ค‘์ˆ˜๊ฐ€ ๋˜์‹ ๊ฒ๋‹ˆ๋‹ค~ ์ถ•ํ•˜๋“œ๋ ค์šฉ~~ใ…‹ใ…‹ 

Starting Loop
Current Count : 0
Loop stopped! 

 

๊ฐ„๋‹จํ•˜์ฃ ??

๋ณ„๊ฑฐ ์—†์Šต๋‹ˆ๋‹ค ใ…Žใ…Ž

 

 

 

Reference : http://www.tutorialspoint.com/javascript/javascript_while_loop.htm