°~°
JCHJava Community | Help. Code. Learn.
•Created by °~° on 1/23/2025 in #java-help
quick help with a simple confusion
int result = 0;
for (int i = 0; i < 4; i++) {
result += 3;
}
System.out.println(result);
vs
int result = 0;
int i = 0;
while (true) {
result += 3; // shorthand for result = result + 3
i++; // shorthand for i = i + 1
if (i == 4) {
break;
}
}
System.out.println(result);
why in the first one when we use i < 4 it prints out 12 but in the second one i == 4 prints out the same thing
9 replies
JCHJava Community | Help. Code. Learn.
•Created by °~° on 1/22/2025 in #java-help
someone explain this code (which i mostly understand
public static void main(String[] args) {
int number = 0;
while (true) {
number = number + 1;
if (number >= 5) {
break;
}
if (number < 5) {
continue;
}
System.out.print(number + " ");
}
System.out.print(number + " ");
}
i get everything in this code yo but i dont understand how the output here works, and ive done a few codes like this such but what da hell
82 replies