Skip to content

Instantly share code, notes, and snippets.

@ShmuelMofrad
Created December 3, 2017 16:37
Show Gist options
  • Save ShmuelMofrad/fa7ccfa31340e3e0a353e35c47fe7e7d to your computer and use it in GitHub Desktop.
Save ShmuelMofrad/fa7ccfa31340e3e0a353e35c47fe7e7d to your computer and use it in GitHub Desktop.
While(true) loops is not bad forever.
public class WhileLoopsTrueForever {
public static void main(String[] args) {
firstPhase();
sum(5, 2017);
secondPhase();
iamOK();
}
private static void firstPhase() {
int counter = 0;
/* it is always true and it's not always good! */
while (true) {
counter++;
System.out.println("counter: " + counter);
if (counter == 5) {
break;
}
}
}
private static void secondPhase() {
boolean runWhile = true;
int counter = 0;
/* it is not always true! */
while (runWhile) {
counter++;
System.out.println("counter-2: " + counter);
if (counter == 5) {
runWhile = false;
}
}
}
private static void sum(int a, int b) {
System.out.println("sum A and B is: " + Integer.sum(a, b));
}
private static void iamOK() {
System.out.println("I'm OK!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment