Hey everybody. I have a question on how to break out of a java loop. Here is a break down of what I am doing. I have 3 arrays "chrs" and "value" and "NumTimes"; "chrs" is an array of characters that has been read in from an input file. Value should be storing unique characters from chrs, and Numtimes will count if a letter has repeated itself. In the end I am looking to construct frequency information.
Example output:
chrs: The quick brown fox jumped over the lazy dog.
value: The quickbrownfxjmpdvlazyg.
NumTimes: 224812.......
(although, since the "t"s are compared in ASCII I am assuming that T and t will be different.)
Here is my code where I am having issues:
//Special Case. First Element
Value[0] = chrs[0];
NumTimes[0] = 1;
int ptr = 1;
System.out.print("\nFirst Values in...\n");
System.out.print("Testing ptr="+ptr+"\n--------\n");
for(int i = 1; i < count;){
System.out.print("Testing i="+i+"\n");
for(int j = 0; j < ptr;){
System.out.print("Testing j="+j+"\n");
System.out.print("Testing ptr="+ptr+"\n");
//Case in which the 2 match
if(chrs[i]==Value[j]){
NumTimes[j]=NumTimes[j]+1;
i++;
}
//They don't match, but more 'j' to check
else if(chrs[i]!=Value[j] && j < ptr){
j++; //check the next 'j'
}
//They don't match, no more 'j' to check; place into value
else if(chrs[i]!=Value[j] && j==ptr){
Value[ptr]=chrs[i];
NumTimes[ptr]=NumTimes[ptr]+1;
ptr = ptr+1;
i++;
}else{
//Poor Man's 'catch' statement System.out.print("Houston, we've had a problem.");
}
}
}
My gut is telling me that my error (which puts me into an infinite loop) is in the first "else if" statement. I thought that by incrementing "j" it would break the current iteration of the loop and advance to the next J. I guess my question is: is there some form of "Next J" function call that will move to the next loop iteration?
Regards,
Dragonfyre
As an FYI "count" is the length of "chrs."