如何在for循环内的while循环中避免意外标识符

我在 while 循环中收到一个意外的标识符。如果我删除 while 循环,我不会收到意外的标识符,但在 javascript 中我不知道如何使此代码工作,因此我可以循环直到 j 小于 y div 2,同时在 while 循环中增加 y


function Xploder(num,bits=1) {

  temp = BigInt(num) + BigInt(1)

  xnum = (temp * BigInt(Math.pow(2, bits)))-1n

  return xnum

}


var y = 3n

var j = 1009n

for (x=0; x<1; x++) {

  while ( (j < y//2) ) 

     y=Xploder(y)

}


Thrown:

     y=Xploder(y)

     ^


SyntaxError: Unexpected identifier

> }


我如何格式化我的代码,这样我就不会在 while 循环中或在 javascript 中得到意外的标识符,我如何正确编写上述代码。


由下面的评论者回答。我正在从 python 切换到 javascript,只是没有注意到我通过不更改为 javascript 使用的正常划分来注释掉。感谢您的回答,我能够解决这个转换问题。再次感谢!


温温酱
浏览 124回答 2
2回答

杨魅力

您正在评论 y 而不是将其分开。function Xploder(num,bits=1) {&nbsp; temp = BigInt(num) + BigInt(1)&nbsp; xnum = (temp * BigInt(Math.pow(2, bits)))-1n&nbsp; return xnum}var y = 3nvar j = 1009nfor (x=0; x<1; x++) {&nbsp; while ( (j < y/2) )&nbsp;&nbsp; &nbsp; &nbsp;y=Xploder(y)}

人到中年有点甜

双正斜杠是您标记评论开始的方式,因此:for (x=0; x<1; x++) {&nbsp; while ( (j < y//2) )&nbsp;&nbsp; &nbsp; &nbsp;y=Xploder(y)}被解析为:for (x=0; x<1; x++) {&nbsp; while ( (j < y y=Xploder(y)}...解释了错误消息。如果要分割,请使用单个 /for (x=0; x<1; x++) {&nbsp; while (j < y/2)&nbsp;&nbsp; &nbsp; &nbsp;y=Xploder(y)}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript