Loops

Loops in Java are a way for the programmer to repeat certain lines of code in succession. For instance, if you wanted to make a count down timer program, either a "while" or a "for" loop would be appropriate in making the timer count down.

A "while" loop is a loop that attempts to continue looping until the condition stated within the "while (condition){" ceases to be true.

A "for" loop is a loop that does more or less the same thing as a "while" loop, but that has a different syntax for running, that being "for ("define int" int x = 0 / x = 50; "define when the loop should stop" x < 10 / x > 10; "define the interval that x increases/decreases" x++/x--)", as opposed to "while (int x > 5){".

While a "for" loop may sound a bit more complicated to you now, you will learn that in reality, "for" loops are significantly better than "while" loops in their own way.

Statements

The main statements you'll need as a beginner are the "if" and "else" statements, and although there are more than just these two, these are the only two I will cover in this beginners guide.

The "if" and "else" statements go hand-in-hand. The "if" statement's main function is to decide whether or not to run a certain segment of code based on whether or not (Decided by the programmer) the Boolean or function within the "if" statement is "true" or "false" (If the condition is an equality, you MUST use two equals signs back to back "==", otherwise you'll get an error). While the "if" statement can exist alone, the "else" statement on the other hand must be accompanied by an "if" statement. The "else" statement does not use the parenthesis as the "if" statement does, as it runs with the only condition being that the accompanying "if" statement has failed to run. You can, on the other hand, code the "else" statement to have conditions, but only if you make it in to an "else if" statement.