naming conventions - Why every for loop starts with int i=0? -
in popular programing world, when write loops this,
for(int = 0; condition; increment or decrement i) {}
my question is, why write int = 0 ? why can't default int = 0 or int b = 0. know possible there history behind int =0 ?
i , j have typically been used subscripts in quite bit of math quite time (e.g., in papers predate higher-level languages, see things "xi,j", in things summation).
when designed fortran, (apparently) decided allow same, variables starting "i" through "n" default integer, , others real (floating point). who've missed it, source of old joke "god real (unless declared integer)".
most people seem have seen little reason alter that. it's known , understood, , quite succinct. every 1 time in while see written psychotic thinks there's real advantage like:
for (int outer_index_variable=0; outer_index_variable < 10; outer_index_variable++) (int inner_index_variable=0; inner_index_variable<10; inner_index_variable++) x[outer_index_variable][inner_index_variable] = 0;
thankfully pretty rare though, , style guides point out while long, descriptive variable names can useful, don't need them, variable's scope line or 2 of code.
source : http://programmers.stackexchange.com/questions/86904/why-do-most-of-us-use-i-as-a-loop-counter-variable
for-loop naming-conventions conventions
No comments:
Post a Comment