How to Loop, 23/100 Days of Code
I hit a wall in my program! Then I flew right over it.
I wanted to use a do while loop to make sure the program continues to obtain information until the zip code no longer appears in the list. I had trouble figuring out how to include the loop. Once again, my troubles lied in the if statements.
When the program confirms the zip code format, it either finds it in the list, or doesn’t. Either way, it returns a similar result; a String. I read through the code again and decided to separate this process from the if statements.
I created a variable outside the if statements to return at the end of the method. If the zip code is found, the proper information will be assigned to the variable. If it is not found, a distinct message will be assigned to the variable.
Regardless of the outcome, a variable is returned. The variable is declared outside the loop in order to maintain a scope broad enough for it to be accessed by both the if statement and the trailing else (click below).
This was a bit of a curve ball. I didn’t plan for it, but I was able to pivot and include this feature with relative ease. Before I proceed to the next step, I’ll reformat output with new code for testing. The older setup makes the output look abysmal (click below).
-CF