+ 1
Loop
Why we use int at the place of initialisation?
5 Answers
+ 16
Often you would use integers as the loop control variable. However, you can use other data types e.g. char.
In C#:
for(char c = 'a'; c <= 'z'; c++)
Console.Write(c);
// Print out all the characters from a to z
+ 11
We are creating new variable with type INT(Whole number), so we can use it within loop.
Also Java is strict typed language, so you can not skip variable declaration.
Second variant: Try to use already created variable, then you will not need to decalre it in 'initialization' list
+ 11
Because loop counts are always integer values.
+ 11
@Hatsy Rei, lol, how so much likes? O.o :D ppl likes u. But it is unfair, you can use classes or other types in loops. Just nit for counting, but for doing something
+ 3
int is a datatype which indicate that Only Integers can be stored in a particular variable.
Other datatypes are:- String,float,double, long ,char etc..