gpt4 book ai didi

java - 在for语句的初始化中可以初始化多少个变量?

转载 作者:搜寻专家 更新时间:2023-11-01 01:28:04 25 4
gpt4 key购买 nike

一个简单的 for 语句是:

 for(int i = 0/*A Optional*/; i < 10/*B Optional*/; i++/*C Optional*/) {
}

现在for语句的初始化代码(A)中可以初始化多少个变量?另外,我将如何在 for 语句的初始化代码 (A) 中初始化这些变量?

最佳答案

想写多少就写多少,但声明仅限于同一类型。 (对于初始化,请参阅下面的扩展和 Wugs 的回答。)

for (int a = 1, b = 2, c = 3 ; ; ) {
break;
}

(可选)ForInit部分可以是:

  1. If the ForInit code is a list of statement expressions (§14.8), the expressions are evaluated in sequence from left to right; their values, if any, are discarded.

  2. If the ForInit code is a local variable declaration, it is executed as if it were a local variable declaration statement (§14.4) appearing in a block.

  3. If the ForInit part is not present, no action is taken.

上面带有声明的示例代码的格式为 for(LocalVariableDeclaration;;)

关于java - 在for语句的初始化中可以初始化多少个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11657341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com