excerpt from Thinking in java 2e:
The comma operator
Earlier in this chapter I stated that the comma operator (not the comma separator, which is used to separate definitions and function arguments) has only one use in Java: in the control expression of a for loop. In both the initialization and step portions of the control expression you can have a number of statements separated by commas, and those statements will be evaluated sequentially.
//: c03:CommaOperator.java
public class CommaOperator {
public static void main(String[] args) {
for(int i = 1, j = i + 10; i < 5;
i++, j = i * 2) {
System.out.println("i= " + i + " j= " + j);
}
}
} ///:~
>>> 在 ? : 中也可以用 "," 吗? k=(k>0)?(p++, k=0):k+1;