some fixes

This commit is contained in:
Ellpeck 2019-10-12 00:05:54 +02:00
parent 6550d2ebcd
commit 7be2feeff1

View file

@ -22,7 +22,7 @@ public class Main {
```
So what we see here is called the `if` condition. It's structured as follows: You write the word `if`, followed by *the condition*, which is wrapped in parentheses `()`. You can then open curly braces `{}`, and any instructions that are written between them will only be executed if your supplied condition holds true.
The condition can be any statement that can either be `true` (correct) or `false` (incorrect). In this case, we're comparing two numbers with each other; there are several other ways to compare two numbers: `>`, `<`, `>=`, `<=` and `==`, the latter of which means "are the two numbers exactly equal".[^2]
The condition can be any statement that can either be `true` (correct) or `false` (incorrect). In this case, we're comparing two numbers with each other; there are several other ways to compare two numbers: `>`, `<`, `>=`, `<=`, `!=` and `==`, where the last two mean "not equal" and "exactly equal".[^2]
An important thing to note at this point is that this behavior is *different* with `String` variables.[^3] Comparing if two strings are equal by using `==` will not result in the behavior you might expect. Instead, you should compare two strings using `equals()` as follows:
```java
@ -119,15 +119,15 @@ As you might be able to tell from that, a `for` loop causes any number of instru
Its structure is pretty similar to the `if` statement's: First, you write the word `for`, followed by some loop instructions inside parentheses `()`, and then you open curly braces `{}` which contain the instructions that should be executed multiple times. The loop instructions contain three parts, which are separated by semicolons `;`:
- `int index = 0;` is the declaration of the *loop variable*: This is the instruction that will be executed *before* the loop starts running.
- `index < 5;` is the *loop's condition*: Before every time the loop's content is run, a check is done to make sure that this condition is still true. If it's not true anymore, the loop stops running.
- `index < 3;` is the *loop's condition*: Before every time the loop's content is run, a check is done to make sure that this condition is still true. If it's not true anymore, the loop stops running.
- `index = index + 1` is the instruction that is executed *after* every time the loop's content has finished running.
So in the case of our loop, the following things happen:
- The `index` variable is declared and set to 0.
- `index < 2` is checked, which is obviously true.
- `index < 3` is checked, which is obviously true.
- The loop's content is run, which causes the print to the console.
- `index = index + 1` is executed, which sets `index` to 1.
- `index < 2` is checked, which is still true.
- `index < 3` is checked, which is still true.
- The loop's content is run again, and so on.
## `break`