Skip to content

Commit b1c2890

Browse files
committed
Fixed typos
1 parent 81c0805 commit b1c2890

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

src/Java-Fundamentals/course/Loops.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The `while` loop is the simplest loop and is used to repeat a part of the progra
99
Here is the structure of a while loop:
1010

1111
```java
12-
while (condition) { // the condition that is evaluated to true or false
12+
while (condition) { // the condition that is evaluated to true or false like an if statement
1313
// Do things here
1414

1515
// Last line of the loop body is the one right before the }
@@ -73,7 +73,7 @@ ______________________________________________________________________
7373

7474
## For each loops
7575

76-
The for each loop runs code for every part of a collection. It will run a loop that is the number of indexes in an [Array](./Arrays.md) or String.
76+
The for each loop runs code for every part of a collection. It will run a loop that is the number of indexes in an [Array](./Arrays.md).
7777

7878
This may be confusing but the format is:
7979
```java
@@ -86,31 +86,28 @@ This splits your array into individual data entries that can be referred to by a
8686

8787
```java
8888
String[] appleTypes = new String[] {"Pink Lady", "Red Delicious", "Granny Smith", "umm I'm out of apple names"};
89+
8990
for (String theTypeOfApple: appleTypes) {
9091
[...]
9192
System.out.println(theTypeOfApple);
9293
} //prints out every item in the array
9394
```
9495
Here we have an array of apple types. The code in for loop runs "for each" type of apple. In this code the type of apple we are currently on is referred to as `theTypeOfApple`. Each time this runs we are on a different entry in the array and the code is done on all of them. Each of these entries is of type `String` and we are calling them `theTypeOfApple` for the for loop. The array we are looping through is called `appleTypes`. That is why we have `String theTypeOfApple: appleTypes` because this runs through the everything in array with each individual String.
9596

96-
Here are some examples:
97-
```java
98-
String name = "Connor";
99-
for (char letter: name) {
100-
//here there can be code where the code runs each character that makes up the String "name". Every character that it runs through will be referred to as "letter" every time the loop goes around.
101-
}
97+
Here is an example:
10298
```java
103-
int[] numbers = new int[] {3, 5, -7, 1}
104-
int total = 0
99+
int[] numbers = new int[] {3, 5, -7, 1};
100+
int total = 0;
101+
105102
for (int number: numbers) {
106-
total += number
103+
total += number;
107104
}
108105
```
109106
This last example adds every integer in numbers together. Also since arrays are often a named a plural noun, using it's singular to refer to each entry makes sense. Here we are referring to each number that is a part of numbers.
110107

111108
______________________________________________________________________
112109

113-
The regular loop can also be used to go through an Array or String but still allowing us to use the index in the code:
110+
The regular for loop can also be used to go through an Array but still allowing us to use the index in the code:
114111
```java
115112
for (int i = 0; i < arrayName.length; i++) {
116113
System.out.println("This is the index: " + i);
@@ -119,6 +116,8 @@ for (int i = 0; i < arrayName.length; i++) {
119116
```
120117
This lets us use both the index and the value (through `arrayName[index]`) in each iteration of the loop. This too will go through every entry into the array.
121118

119+
______________________________________________________________________
120+
122121
## Resources
123122

124123
[W3Schools While Loop](https://www.w3schools.com/java/java_while_loop.asp)\

0 commit comments

Comments
 (0)