# 2 for loops inside a String function

**URL:** <https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669>\
**Category:** Coding Questions\
**Created:** [January 1, 2021, 3:35pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669 "2021-01-01T15:35:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [January 1, 2021, 3:35pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669/1 "2021-01-01T15:35:37Z")

</div>

why is this not working?  
 ![WhatsApp Image 2021-01-01 at 14.31.10](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/2/2dc5a83a6683c51cf09f8cf6f440d7929c689dd0.jpeg)  
yea, I know I dont need that boolean finished in the beginning

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 1, 2021, 3:46pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669/2 "2021-01-01T15:46:46Z")

</div>

You can `throw` a RuntimeException inside your `catch () {}` block as a workaround:  
`throw new RuntimeException("192.168." + i + '.' + j);`

> **[RuntimeException (Java SE 11 & JDK 11 )](https://docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/lang/RuntimeException.html)**

---

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [January 1, 2021, 4:38pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669/3 "2021-01-01T16:38:39Z")

</div>

that isn’t the problem, my problem is that it says the code at the end is unreachable, but thanks

 ![grafik](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/5/52fa30dfd0aa9b8d1cfe89137117e18f5d943dc5.png)

---

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [January 1, 2021, 4:54pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669/4 "2021-01-01T16:54:04Z")

</div>

The line `return null;` is the end of your `getServerAdress()` function. There’s no way that the code after the return statement can be reached!

Each line of code is like a step in following a recipe. Essentially, what you’ve told the computer to do is to stop doing things, and then do something more. This confuses it. Did you want the function to stop at the return statement? Or did you want it to print “SERVER NOT FOUND” before it stops? You can’t have it both ways! That’s what your error means.

---

<div class="post-metadata">

**Author:** ![JoLi](https://avatars.discourse-cdn.com/v4/letter/j/e495f1/32.png) [@JoLi](https://discourse.processing.org/u/JoLi)\
**Post date:** [January 1, 2021, 4:54pm UTC](https://discourse.processing.org/t/2-for-loops-inside-a-string-function/26669/5 "2021-01-01T16:54:57Z")

</div>

oh i didnt think of that, thanks… 😆
