<aside>
💡 loops, conditionals, classes
</aside>
conditionals
-
perform different actions depneidng on whether a boolean condition evaluates to true or false
-
if condition is true, one set of statement is executed. otherwise, another set of statements is executed


multiple alternatives
- more than two cases, resulting in code w multiple branches
- if you have multiple if statements, test against the largest cutoff first

relational operators

comparing strings: .equals() vs ==
-
when comparing strings in a conditional statement, make sure to check for equality using .equals() and not ==
-
== checks to see whether the strings are stored in the same location, not whether their contents are the same

boolean operators
- used to combine multiple boolean conditions
- && (and) operator returns true when both conditions are ture
- || (or) operators returns true if at least one condition is true
- ! (not) operator negates or inverts a condition

loops
-
execute instructions until goal is reached
-
while loops: as long as Boolean condition is true, the statements inside the while statement are executed
- loop condition is checked first and before every time the loop iterates
- structure:
while (condition)...

- better to use when you don't know exactly how many times the loop will run
-
for loops: used when a value runs from starting point to an ending point with a constant increment or decrement (step size)
for (initalization; condition; update)...
-
initalization is executed once, the condition the checked before each iteration, and the update is executed after each iteration

-
better to use when you know before hand how many times the loop will be run
objects and classes
what are classes?
- a unit of organization in your code (one public class per file)
- a blueprint for the objects you are mkaing
- classes we already know: Math, String
- tip: you can usually identify a class because names are capitalized
- Math.pow(4,3); or String name = "Chianna";
3 main components of a class
- fields/instance variables - attributes
- hair color, height, weight
- constructors - instatiates your object, initalizes the instance variables
- methods - actions
variables and data types
- local variables v. instance variable
- primitive data types are in lower case: int, boolean, char, etc
- you cannot call methods in them
- must always declare before you use the variable
instance variables