jsÖÐforÑ»·ÔõôÓÃ
javascript ÖÐ for Ñ»·ÊÇÒ»ÖÖ¿ØÖÆÁ÷Óï¾ä£¬ÓÃÓÚÖظ´Ö´ÐдúÂë¿éÖ±µ½Ä³¸öÌõ¼þ²»ÔÙÖª×ã¡£for Ñ»·µÄÓ﷨Ϊ£ºfor (initialization; condition; increment/decrement) { // Ñ»·Ìå }£¬ÆäÖУºinitialization£ºÑ»·×îÏÈʱִÐеijõʼ»¯´úÂë¡£condition£ºÑ»·Ã¿´ÎÖ´ÐÐÇ°¼ì²éµÄÌõ¼þ£¬ÈôΪÕæÔò¼ÌÐøÖ´ÐÐÑ»·£¬²»È»¿¢ÊÂÑ»·¡£increment/decrement£ºÑ»·Ã¿´ÎÖ´Ðкó¸üеıí´ïʽ£¬Ò»Ñùƽ³£ÓÃÓÚÔöÌí»ò¼õСѻ·±äÁ¿¡£
JavaScript ÖÐ for Ñ»·µÄÓ÷¨
For Ñ»·ÊÇÒ»ÖÖ¿ØÖÆÁ÷Óï¾ä£¬ÓÃÓÚÖظ´Ö´ÐдúÂë¿é£¬Ö±µ½Ä³¸öÌõ¼þ²»ÔÙÖª×ã¡£ÔÚ JavaScript ÖУ¬for Ñ»·Óï¾äµÄÓï·¨ÈçÏ£º
for (initialization; condition; increment/decrement) { // Ñ»·Ìå }
µÇ¼ºó¸´ÖÆ
ÆäÖУº
initialization£ºÑ»·×îÏÈʱִÐÐÒ»´ÎµÄ³õʼ»¯´úÂë¡£
condition£ºÑ»·Ã¿´ÎÖ´ÐÐÇ°¼ì²éµÄÌõ¼þ£¬ÈôÊÇΪÕæÔò¼ÌÐøÖ´ÐÐÑ»·£¬²»È»¿¢ÊÂÑ»·¡£
increment/decrement£ºÑ»·Ã¿´ÎÖ´Ðкó¸üеıí´ïʽ£¬Í¨³£ÓÃÓÚÔöÌí»òïÔÌÑ»·±äÁ¿¡£
ʾÀý£º
// ´òÓ¡Êý×Ö 1 µ½ 10 for (let i = 1; i <p>ÔÚÕâ¸öʾÀýÖУº</p>
µÇ¼ºó¸´ÖÆ
initialization£ºlet i = 1 ³õʼ»¯Ñ»·±äÁ¿ i Ϊ 1¡£
condition£ºi
increment£ºi++ ÔÚÿ´ÎÑ»·ºó½« i ¼Ó 1¡£
×¢ÖØ£º
Ñ»·±äÁ¿¿ÉÒÔÊÇÈκÎÓÐÓÃµÄ JavaScript ±äÁ¿Ãû¡£
³õʼ»¯ºÍÔöÁ¿²¿·Ö¿ÉÒÔΪ¿Õ¡£
ÈôÊÇ initialization Ϊ¿Õ£¬ÔòÌåÏÖûÓгõʼ»¯´úÂë¡£
ÈôÊÇ condition Ϊ¿Õ£¬ÔòÑ»·½«ÎÞÏÞÆÚµØÖ´ÐС£
ÈôÊÇ increment Ϊ¿Õ£¬ÔòÑ»·»áÒ»Ö±Ö´ÐУ¬Ö±µ½ condition ʧ°Ü¡£
ÒÔÉϾÍÊÇjsÖÐforÑ»·ÔõôÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡