summaryrefslogtreecommitdiffhomepage
path: root/java.html.markdown
diff options
context:
space:
mode:
Diffstat (limited to 'java.html.markdown')
-rw-r--r--java.html.markdown22
1 files changed, 21 insertions, 1 deletions
diff --git a/java.html.markdown b/java.html.markdown
index cdcf620c..3d0cb1d7 100644
--- a/java.html.markdown
+++ b/java.html.markdown
@@ -3,6 +3,7 @@
language: java
contributors:
- ["Jake Prather", "http://github.com/JakeHP"]
+ - ["Madison Dickson", "http://github.com/mix3d"]
filename: LearnJava.java
---
@@ -210,7 +211,19 @@ public class LearnJava {
//Iterated 10 times, fooFor 0->9
}
System.out.println("fooFor Value: " + fooFor);
-
+
+ // For Each Loop
+ // An automatic iteration through an array or list of objects.
+ int[] fooList = {1,2,3,4,5,6,7,8,9};
+ //for each loop structure => for(<object> : <array_object>)
+ //reads as: for each object in the array
+ //note: the object type must match the array.
+
+ for( int bar : fooList ){
+ //System.out.println(bar);
+ //Iterates 9 times and prints 1-9 on new lines
+ }
+
// Switch Case
// A switch works with the byte, short, char, and int data types.
// It also works with enumerated types (discussed in Enum Types),
@@ -233,6 +246,13 @@ public class LearnJava {
break;
}
System.out.println("Switch Case Result: " + monthString);
+
+ // Conditional Shorthand
+ // You can use the '?' operator for quick assignments or logic forks.
+ // Reads as "If (statement) is true, use <first value>, otherwise, use <second value>"
+ int foo = 5;
+ String bar = (foo < 10) ? "A" : "B";
+ System.out.println(bar); // Prints A, because the statement is true
///////////////////////////////////////