int Cnt = 4;
for(int i=0; i<Cnt; i++) {
}
Inside this loop I want to make different decisions based on the value of i.
So what is the best way to implmenet this ??
Should i use the following way ??
for(int i=0; i<Cnt; i++) {
if (i==0) {
// some code
}
else if(i==1) {
// some code
}
}
Or will this way it will look good ??
for (int i=0; i<Cnt; i++) {
String str = Bag[0].value ;
String str22 = Bag[1].value
}
I want to ask is that how can I know what the maximum length of array can be?
What is the least error prone way for doing this?
Bag.length, rather than duplicating that information in another variable.