I have this piece of code:
String chords = "I-iii-IV-iv";
String character;
String nextCharacter;
String finalChord;
String chordString;
for(int i = 0; i<chords.length(); i++) {
char c = chords.charAt(i);
character= Character.toString(c);
nextCharacter= Character.toString(chords.charAt(i+1));
do {
if(nextCharacter.equals("-")) {
//Chord is finished
finalChord = character;
chordString += finalChord += " ";
} else {
//Chord hasn't finished yet, repeat do-while loop
}
} while (!character.equals("-"));
What this wants to do is loop through the initial String "I-iii-IV-iv".
- If the character isn't a "-" but the next character is, add the actual chord to a final String.
- If the character is a "-", add it to a final String.
- If nor the character or the next character are "-" (which means you are in the "iii" case, for example), add this character to a string and loop through the for again until next character is a "-", then add the actual chord to a final String.
I don't know if that is clear enough, I hope it is. Thanks in advance!
Edit: What I'm wishing to do is looping through a String until the next character is "-". How can I do it?
Edit 2: Taken Hovercraft Full Of Eels' advice, I have tried to use a do-while loop. I find myself in the same situation, I want to repeat the loop if a certain condition is given (Nor the character or the next character are a "-".
Let me expand my explanation: When that condition returns true
, i want to check it again for the next character, and so on until the actual character is a "-".