Android - For loop not incrementing integer
I have a for loop which allows me to work out a level of 开发者_如何学Pythona player, however the level doesn't get incremented after each loop, heres my code:
int[] Level_XP = new int[] {0,Level1, Level2, Level3, Level4, Level5, Level6, Level7, Level8, Level9, Level10,
Level11, Level12, Level13,Level14, Level15, Level16, Level17, Level18, Level19, Level20,
Level21, Level22, Level23, Level24, Level25, Level26, Level27, Level28, Level29, Level30,
Level31, Level32, Level33, Level34, Level35, Level36, Level37, Level38, Level39,Level40,
Level41, Level42, Level43, Level44, Level45, Level46, Level47, Level48, Level49, Level50};
int level;
for (level = 1; User_XP < Level_XP[level];level++) { }
Minimum_Percentage = Level_XP[level];
Maximum_Percentage = Level_XP[level+1];
User_Level.setText(Integer.toString(level));
I have intialised all the integers and there is an array being used, can anyone help me to actually increase the level after each loop? As this way the level only stays at level 1.
Your for-loop is empty. That's why nothing happens there.
for (level = 1; User_XP < Level_XP[level];level++) { }
You didn't write anything in the curly braces. So your loop will be empty.
int level ;
for (level = 1; User_XP < Level_XP[level];level++) { }
Minimum_Percentage = Level_XP[level];
Maximum_Percentage = Level_XP[level+1];
User_Level.setText(Integer.toString(level));
There are quite a few problems with the above statements, even some code goes in the for
loop.
What if
User_XP < Level_XP[level];
is always true ? You pass the array length and an exception is generated.If condition satisfied for the very last element of the
Level_XP
infor
loop, thenMaximum_Percentage = Level_XP[level+1]; // This causes exception
精彩评论