【发布时间】:2015-12-03 21:17:35
【问题描述】:
嗨,正如我在标题中提到的,我的代码中的循环中有一堆循环,其中大多数使用变量来循环遍历内容。我称我的变量为 ia,然后是 ib,然后是 ic,依此类推。命名这些变量的好形式是什么?
这里有一些代码可能有助于理解我在说什么
for (var ic = 0; ic <= currState.length; ic++) { //loop the columns and check if there is a
if (currState[ic] == 0) {
for (var id = 1; id <= currState.length; id++) { //loop the rows of a column
tryPos = [id, ic + 1]; //id -> row | ic -> column
if (checkClash(currState, tryPos) == false) {
currState[ic] = id
break;
}
}
}
}
【问题讨论】:
-
row和col对我来说似乎很不错的名字 -
我倾向于以辛普森角色的名字命名它们,从 Maggie 开始。没关系。计数器变量的名称很少影响清晰度。
标签: javascript loops variable-names