+ 1

Loop

Why we use int at the place of initialisation?

2nd Mar 2017, 12:18 PM
Krishna Priya
Krishna Priya - avatar
5 odpowiedzi
+ 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
2nd Mar 2017, 3:58 PM
Jafca
Jafca - avatar
+ 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
2nd Mar 2017, 12:27 PM
WittyBit
WittyBit - avatar
+ 11
Because loop counts are always integer values.
2nd Mar 2017, 12:50 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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
2nd Mar 2017, 3:31 PM
WittyBit
WittyBit - avatar
+ 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..
2nd Mar 2017, 12:37 PM
Meharban Singh
Meharban Singh - avatar