For loop you queer.
Loops in Java are very useful for those who want to implement things that repeat them self. For instance, we would not use a loop in this situation:
Alright, I have to admit this is a bad example but hey. Anyways, lets say that we wanted this integer to grow 10 times. Now this is where the loop comes in handy. Every loop must begin with something like the following.
By the way, this is the for loop.
Please note that the number 10 can be changed to match certain situations. Anyhow, this basically means for the loop, it will then set the integer to 0 and then it'll count to 10 because of i++. Hopefully, you understood what that meant.
Now, here is one last example to clear most things up with you. This is a better example then the other one because you will actually see this in some servers.
What this does is that it replaces the line of text with nothing. But, it's pointless to write out the same thing over again. So what you would use is a loop to make things smaller and easier to edit.
What this does it that it'll basically replace the line of text 8 times with nothing given it the same effect as the code a bit above.
Loops in Java are very useful for those who want to implement things that repeat them self. For instance, we would not use a loop in this situation:
Code:
badExample += 1; badExample += 1;
By the way, this is the for loop.
Code:
for (int i = 0; i < 10; i++) {
Now, here is one last example to clear most things up with you. This is a better example then the other one because you will actually see this in some servers.
Code:
client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString(""); client.stream.writeString("");
Code:
for (int i = 0; i < 8; i++) { client.stream.writeString(""); }