Originally posted by balajee annamalai: I need to know why option (a) is working and not option (b) what is the difference?
Can any one please expain this?
The difference is that in variant b you have a single line as the body of the for loop, and such a single line body may not declare variables. This is allowed only inside a block enclosed in curly brackets, as in variant a. For such an enclosed block, it does not matter if its only line declares a variable, at least not in terms of a compiler error. You might get a warning, though: "the local variable j is never read".