MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/rim2oh/i_made_a_rainbow/
r/badcode • u/YogurtclosetNo2622 • Dec 17 '21
6 comments sorted by
11
Ouch. These while(true) loops would make my computer science teacher turn in his grave.
while(true)
2 u/doh007 Dec 17 '21 while(true) loops that are ended using a break and two exceptions
2
while(true) loops that are ended using a break and two exceptions
break
5
throw new FunnyException();
Apparently didn't learn about labels and breaking to them. But I don't blame them, labels a niche feature that can only be used in cases like this
1
Image Transcription: Code
@Override public void run(){ try { while (true) { try{ ArrayList<String> request=new ArrayList<String>(); while (true) { String line = ""; while (true) { int current = input.read(); if (current == -1_ { throw new IDException(); } char c = (char) current; if (c == '\n') break; line +=(c); } if(line.equals("\r")) { String[] r = new String[request.size()]; for(int i=0;i<r.length;i++){ r[i]=request.get(i); } handle(r); throw new FunnyException(); } request.add(line); } }catch (FunnyException e){} } }catch(IOException e){} } public void handle(String[] request){ RequestHandler.sendFile(output,request[0].split(" ")[1]); } } class FunnyException extends Exception{}
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
Oh dear! Using Exceptions to break out of the outer loops. That's fairly evil.
Use labels instead:
public class Test { public static void main(String[] args) { outerloop: for (int i=0; i < 5; i++) { for (int j=0; j < 5; j++) { if (i * j > 6) { System.out.println("Breaking"); break outerloop; } System.out.println(i + " " + j); } } System.out.println("Done"); } }
11
u/humleflue Dec 17 '21
Ouch. These
while(true)loops would make my computer science teacher turn in his grave.5
u/EXAngus Dec 17 '21
throw new FunnyException();
2
u/MattiDragon Dec 20 '21
Apparently didn't learn about labels and breaking to them. But I don't blame them, labels a niche feature that can only be used in cases like this
1
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Dec 17 '21
Image Transcription: Code
I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
1
u/KrakenOfLakeZurich Dec 29 '21
Oh dear! Using Exceptions to break out of the outer loops. That's fairly evil.
Use labels instead: