括号中的四个“东西”的for循环是如何工作的? [英] How does a for-loop with four 'things' in the parenthesis work i Javascript?

查看:167
本文介绍了括号中的四个“东西”的for循环是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一些代码 https://stackoverflow.com/a/2922778/2176900 ,这对于(i = 0,j = nvert-1; i< nvert; j = i ++){... b
$ b

 

我不明白它在括号内有四件事情时会做什么( i = 0,j = nvert-1,i $ b

谢谢

解决方案

它没有四件事;它仍然有三个。




  • 预循环语句

    i = 0,j = nvert-1


  • 迭代条件 <
    i <


  • 迭代后操作

    j = i ++




预循环语句实际上应该是:

var i = 0,j = nvert-1

记住我们可以声明多个变量在一个单一的声明。这就是发生在这里的事情。


I came across some code here https://stackoverflow.com/a/2922778/2176900 that started off like this:

for (i = 0, j = nvert-1; i < nvert; j = i++) {...`

and I don't understand what it does when it has four things within the parenthesis ("i = 0", "j = nvert-1", "i < nvert" and "j = i++"). I've obviously been trying to google this, but can't seem to find any answers. I'm sure if I just knew what the things in the parenthesis was called I'd be glad.

Thanks

解决方案

It doesn't have four things; it still has three.

  • The pre-loop statement
    i = 0, j = nvert-1

  • The iteration condition
    i < nvert

  • The post-iteration action
    j = i++

That pre-loop statement is actually probably supposed to read:
var i = 0, j = nvert-1

Remember that we can declare multiple variables in a single declaration. That's what's happening here.

这篇关于括号中的四个“东西”的for循环是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆