You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Above is a example of how functions might be used. You can see that it will return a boolean of whatever the `retroReflectiveGP` sensor sees. Because it uses private, you would not be able to call this function to get weather the gp is present from outside the class.
53
+
Above is a example of how functions might be used. You can see that it will return a boolean of whatever the `retroReflectiveGP` sensor sees. Because it uses private, you would not be able to call this function to get whether the gamepiece is present from outside the class.
Copy file name to clipboardExpand all lines: lessons/hello-world.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ Output
21
21
Hello World
22
22
```
23
23
24
-
The code above, when run, will display "Hello World" in the terminal. Although not the most exciting result, the code to do it might look intimidating. Let's discuss what is going on here.
24
+
The code above, when ran, will display "Hello World" in the terminal. Although not the most exciting result, the code to do it might look intimidating. Let's discuss what is going on here.
25
25
26
26
##### Curly Braces
27
27
Curly braces `{}` define code blocks. There are 2 sets of them in this program. They are meant to encapsulate code within a program.
@@ -40,7 +40,7 @@ This is what you are probably thinking about when you think of code. It's what a
40
40
```java
41
41
System.out.println("Hello World");
42
42
```
43
-
What this line does it put what's between the parentheses onto the screen. In this case `"Hello World"`, which is what we see when we run the program.
43
+
This line puts what's between the parentheses onto the screen. In this case,`"Hello World"`, which is what we see when we run the program.
44
44
45
45
At the end of every statement, we put a semicolon `;` to tell the computer that our statement is complete.
Copy file name to clipboardExpand all lines: lessons/logic.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,7 @@ Here are some comparison operators:
25
25
-`||`: Or (True: `(1 == 1) || (2 != 2)`, checks if 1 is equal to 1 **or** 2 is equal to 2)
26
26
-`^`: Xor (True: `(1 == 1) ^ (2 != 2)`, True if **only one** of the conditions is true)
27
27
28
-
### Here's some examples:
28
+
### Here are some examples:
29
29
```java
30
30
// Reads like: "if one plus one equals two"
31
31
if (1+1==2) {
@@ -42,7 +42,9 @@ if (1 + 1 == 2 && 3 + 3 == 6) {
42
42
System.out.println("Math is still mathin'");
43
43
}
44
44
```
45
-
Variables can be used in `if` statements as well, assuming that they are `boolean`'s.
45
+
46
+
Variables can be used in `if` statements as well, as long as they are `boolean`'s.
47
+
46
48
```java
47
49
boolean valid =1==1;
48
50
if (valid) {
@@ -61,8 +63,8 @@ if (elevator.atBottomHardStop() || elevator.atUpperHardStop()) {
61
63
currentMotorState =MotorState.kSTOP;
62
64
}
63
65
```
64
-
### A Amendum for Non-Primative Types (For Those Who Care)
65
-
Due to the way that java works, when you compare a non-primative type to anything else you are not comparing the value of the variable, but insted the address to the memory of the variable. Some of the consequences of this are that code like `String("abc") == "abc"`are false (String is a non primative type). For strings and others, you can do `String("abc").equals("abc")` to get it to work.
66
+
### A Addendum for Non-Primative Types (For Those Who Care)
67
+
Due to the way that java works, when you compare a non-primative type to anything else you are not comparing the value of the variable, but insted the address to the memory of the variable. Some of the consequences of this is that code like `String("abc") == "abc"`is false (String is a non primative type). For strings and others, you can do `String("abc").equals("abc")` to get it to work.
66
68
##### For loops
67
69
You can use loops to run code more than once without copy+pasting 800 lines. A straightforward way to do this is a `for` loop. `for` loops run a pre-specified amount of times, defined in the parentheses after `for`. A common syntax you will see is defining a new variable (often `i`), then setting a condition (while `i` is less than `5`), and setting a rule to be followed every loop (commonly `i++`, which increments `i` by 1).
This function's y value is always equal to 3 times its x value. Let's see what this would look like in Java.
13
+
This function's y value is always equal to 3 times its x value.
14
+
15
+
## Java Function
16
+
17
+
Let's see what that function would look like in Java.
14
18
15
19
```java
16
20
double f(double x) {
17
-
return x *3.0;
21
+
return x *3.0d;
18
22
}
19
23
```
20
24
21
25
The first `double` represents the `return` type. This is to signify that the function `return`s a decimal value. `f` is our name. You would usually use something more descriptive such as `triple`. The `double x` is the argument, we specify type and name. It's the x in f(x). The `{ ... }` shows the inside of the function, anything in here happens when the function is 'called'. `return` is often the final line of functions. That's where you put whatever you want to come out of the function, a `double` in our case. `return` additionally ends a functions processing and 'return's to wherever you call it from. Let's see why we want a `return`.
22
26
23
27
```java
24
-
double startNumber =6.0;
28
+
double startNumber =6.0d;
25
29
26
30
double endNumber = f(startNumber); // This will evaluate to 18.0
27
31
```
@@ -31,8 +35,8 @@ This hopefully explains functions. Some more examples are below:
Copy file name to clipboardExpand all lines: lessons/types.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Types are these indicators of, well, type. A real world example could be the typ
13
13
boolean correct =true;
14
14
```
15
15
16
-
This example's type is `boolean`. Boolean (also known as bool) values can hold either `true`, or `false`. This is seen with `= true`. Anything other than valid values on the right side of that `=` will probably cause an error. Let's go over some more simple types.
16
+
This example's type is `boolean`. Boolean (also known as bool) values can hold either `true`, or `false`. This is seen with `= true`. Anything other than true or false values on the right side of that `=` will probably cause an error. Let's go over some more simple types.
0 commit comments