Preamble :)
Have you ever tried to execute your code? :)
- You have a bug: outer loop will run out of list bounds.
- Checking for list size before iterating through it is usually unnecessary.
- I don't see any code to sort list before executing updateScores. Your code will provide unexpected results on unsorted lists.
- You are using strings now. Sorting array of strings is definitely not what you want. Consider using structs with integers for high scores values.
Answering your question
You can just start inner loop from outer loop and use break statement. See example:
public void updateScores() { // loop through each array in the list for (int i = 0; i < list.Count(); i++) { string[] lineData = list[i]; if (lineData[1] == difficulty) { if (score > Convert.ToInt32(lineData[0])) { // if the score is higher than one of the saved highscores remove all lower score down one index for (int j = list.Count() - 1; j > scoreIndex; j--) { // continue } break; } } } }
Negating conditions can simplify the code:
public void updateScores() { // loop through each array in the list for (int i = 0; i < list.Count(); i++) { string[] lineData = list[i]; if (lineData[1] != difficulty) continue; if (score <= Convert.ToInt32(lineData[0])) continue; // if the score is higher than one of the saved highscores remove all lower score down one index for (int j = list.Count() - 1; j > scoreIndex; j--) { // continue } break; } }