在设置变量时使用变量
我想这样枚举一个变量:
$x = 0
Do
$x+=1
$Day$x = True
Until $x = 7
上面的代码在 $Day$x
上返回一个语法错误(因为它只应该在命令中看到一个变量)。所以基本上,我想要 $Day1 = True
、$Day2 = True
等等。有办法做到这一点吗?
I want to enumerate a variable as so:
$x = 0
Do
$x+=1
$Day$x = True
Until $x = 7
The above returns a syntax error on $Day$x
(because it's only supposed to see one variable in the command). So basically, I want $Day1 = True
, $Day2 = True
, so on and so forth. Is there a way to accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
欢迎来到奇妙的数组世界。
实际上,您可以使用 $Day1、$Day2、$Day3 执行最初描述的操作,但这将是一种非常糟糕的编程实践,我个人强烈建议不要这样做。话虽这么说,使用赋值函数是可以实现的。你会因为完全错误的原因而使用它。但为了完整起见,方法如下:
Welcome to the wonderful world of arrays.
You can actually do what you originally described with $Day1, $Day2, $Day3 but it would be a very bad programming practice and I personally strongly discourage it. That being said, it is possible with the Assign function. You'd be using it for totally the wrong reason. But for completeness, here's how: