์ž~ ์˜ค๋Š˜์€ for ๋ฃจํ”„์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

 

for ๋ฃจํ”„์™€ while๋ฃจํ”„๋Š” 100% ๋ฐ”๊ฟ”์น˜๊ธฐ๊ฐ€ ๊ฐ€๋Šฅํ•œ ๋…€์„๋“ค์ž…๋‹ˆ๋‹ค. ์–ด๋–ค ์ƒํ™ฉ์—์„œ ์–ด๋–ค ๋ฐ˜๋ณต๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š๋ƒ๋Š” ๊ฐœ๋ฐœ์ž์ธ ์—ฌ๋Ÿฌ๋ถ„๋“ค์—๊ฒŒ ๋‹ฌ๋ ค์žˆ์Šต๋‹ˆ๋‹ค!!  

์šฐ์„  ๋ฌธ๋ฒ•๋ถ€ํ„ฐ ํ™•์ธํ•ด์•ผ๊ฒ ์ฃ ? ์–ด๋–ป๊ฒŒ ์ƒ๊ธด๋†ˆ์ธ์ง€ ์•Œ์•„์•ผ ๋ญ˜ ์จ๋จน๋”๋ผ๋„ ์จ๋จน์ฃ  ใ…‹ใ…‹ 

 

for ( ์ดˆ๊ธฐํ™” ; ์กฐ๊ฑด๋ฌธ ; ๋ฐ˜๋ณต์‹คํ–‰๋ฌธ ){
     ์กฐ๊ฑด๋ฌธ์ด ์ฐธ์ธ ๋™์•ˆ ์‹คํ–‰๋˜์–ด์•ผ ํ•  ๋ฌธ์žฅ
}

์—ญ์‹œ ์šฐ๋ฆฌ๋Š” ์˜ˆ์ œ๊ฐ€ ์žˆ์–ด์•ผ ๋ญ˜ ์•Œ๊ฒƒ ๊ฐ™์•„์š” ๊ทธ์ฃ ์ž‰?
<script type="text/javascript">
<!--
var count;
document.write("Starting Loop" + "<br />");
for(count = 0; count < 10; count++){
  document.write("Current Count : " + count );
  document.write("<br />");
}
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! 

 

์–ด๋•Œ์š”? ์‰ฝ์ฃ ? ์–ด๋ ค์šฐ์‹œ๋‹ค๊ตฌ์š”? ๊ทธ๋Ÿผ ์„ค๋ช…์„ ์ข€ ํ•ด๋“œ๋ฆด๊ฒŒ์š”.

 

for ( count = 0 ; count < 10 ; count++ ) : for๋ฃจํ”„๋ฅผ ์‹œ์ž‘ํ•˜๋Š” ๋ถ€๋ถ„์ž…๋‹ˆ๋‹ค. ๋ณ€์ˆ˜ count๋ฅผ 0์œผ๋กœ ์ดˆ๊ธฐํ™” ํ•ฉ๋‹ˆ๋‹ค. count๋ณ€์ˆ˜์˜ ๊ฐ’์ด 10๋ณด๋‹ค ์ž‘์„ ๋™์•ˆ ์‹คํ–‰ํ•˜๋ผ๋Š” ์กฐ๊ฑด์„ ์คฌ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ ๋‚˜์„œ ๋งค ๋ฃจํ”„๊ฐ€ ๋๋‚˜๋ฉด count๋ฅผ 1์”ฉ ์ฆ๊ฐ€์‹œํ‚ค๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์—ฌ๊ธฐ์„œ ์„ธ๋ฏธ์ฝœ๋ก  ( ; ) ์žŠ์–ด๋จน์ง€ ์•Š๋„๋ก ์กฐ์‹ฌํ•˜์„ธ์š”.

๋ฌธ๋ฒ•์ด ์–ด๋ ต๋‹ค๋ฉด ์—ฐ์Šต๋งŒ์ด ๋‹น์‹ ์„ ์‚ด๋ฆด ์ˆ˜ ์žˆ์œผ๋‹ˆ ์—ฐ์Šตํ•˜์„ธ์š”. ใ…‹ใ…‹

 

 

์ž, ๋˜ ๋‹ค๋ฅธ for ๋ฃจํ”„๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ์ฒด๋ฅผ ์ด์šฉํ•˜๋Š” ๊ฒƒ์ธ๋ฐ์š”~ ํ˜•์‹์„ ํ•œ๋ฒˆ ๋ณผ๊นŒ์š”?

 

 

for (๋ณ€์ˆ˜๋ช… in ๊ฐ์ฒด){
  ์‹คํ–‰ํ•  ๋ฌธ์žฅ
}

 

 

 

์•„๋ž˜ ์˜ˆ์ œ๋Š” ์›น๋ธŒ๋ผ์šฐ์ €์˜ Navigator๊ฐ์ฒด์— ์žˆ๋Š” ์†์„ฑ์„ ์ถœ๋ ฅํ•˜๋Š” ๊ธฐ๋Šฅ์„ for๋ฃจํ”„๋กœ ๊ตฌํ˜„ํ•ด๋†“์€ ๊ฒƒ์ž…๋‹ˆ๋‹ค. 

<script type="text/javascript">
<!--
var aProperty;
document.write("Navigator Object Properties<br /> ");
for (aProperty in navigator)
{
  document.write(aProperty);
  document.write("<br />");
}
document.write("Exiting from the loop!");
//-->
</script>

 

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์˜ค๊ฒ ์ฃ ? ์•„๋‹Œ๊ฐ€์š”? ๋งž๋‚˜? ํ™•์ธํ•ด๋ณด์„ธ์š”~~ ^___^ 

Navigator Object Properties
appCodeName
appName
appMinorVersion
cpuClass
platform
plugins
opsProfile
userProfile
systemLanguage
userLanguage
appVersion
userAgent
onLine
cookieEnabled
mimeTypes
Exiting from the loop! 

 

 

 

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