Please enable JavaScript.
Coggle requires JavaScript to display documents.
Decision Structures - Coggle Diagram
Decision Structures
Logic & Comparisons
Logical Operators
The && operator checks if two statements are both true; if one or both is false, the boolean expression returns false
The || operator checks if one or both statements are true; if both are false then the boolean expression returns false
The ! operator reverses the truth value of a statement; if a statement is true, the ! operator returns false
Order of Precedence
! operator has first precedence, followed by */%, then +-, < > <= and >=, then == !=. followed by && then || then assignment and combined assignment operators
Comparing String Objects
-
To compare them correctly, use the equals method: string 1.equals(string2)
CompareTo method can compare different strings; 0 means equality, 1 means greater than and -1 means lower than
Comparing Characters
Characters are stored as 16 bit unicode strings and their values based on where they are stored can be compared with if statements
For instance, 'A' is less than 'C' because it has a lower order on the unicode chart than 'C'
Switch Statement
-
Break statement
The break statement ends the execution of the code segment and exits the loop. If there is no break statement, the code continues to execute until there is one
Default statement
The default statement is optional and executes if none of the above matched, or if there is no break statement above it
If statements
If/Else-if statements
If Statements
If statements test a boolean expression and execute a block of code based on if that boolean is true
Boolean Expressions
-
Statements with one equal sign indicate an assignment statement while two equal signs indicate a comparison in a boolean expression
If statements use relational operations to compare two or more statements; examples include <, >, ==, etc
Rules of thumb for style
place the first line of the if statement one line below the if statement if there's no semicolon, and indent it
-
-
Flags
Flags are boolean variables that store a boolean value set by if statements, and can be used as expressions in future if statements
-
Nested if statements
Nested if statements are if statements within another if statement that executes only when the original is true
-
-