Skip to content
Coding Fanatic
  • Android Development
  • News and Reviews
  • Road2Pro
  • Tutorials
  • Services
  • About

How to Loop, 23/100 Days of Code

  • April 2, 2019
  • by Richard Clarke

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

Related

Off With the Head! 22/100 Days of Code
Undercover Bugger, 24/100 Days of Code
Richard Clarke
Richard is currently a developer using Java and Android Studio to build custom applications for Android. Richard tutored in mathematics at Montgomery College, and worked in Information Technology before entering the Software Development industry as a Quality Engineer.
100daysofcode coding Java Prog

Related articles

Your New Favorite Stopwatch App!…
Two for Two BABY! 7…
…But the App is for…
Play Store Blues – 5…
Top 4 Tips for Android…
No Dice – 3 of…

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • GitHub
  • YouTube
  • X
  • Instagram
  • LinkedIn
My Tweets

Join the mailing list!

This field is required.

Check your inbox or spam folder to confirm your subscription.

Follow me on social media!

  • X
  • GitHub
  • LinkedIn
  • YouTube

Archives

Theme by Colorlib Powered by WordPress