Introduction to For Loops Flashcards
what is a code block?
a code block is the curly brackets {}, this indicates the start and stop of a block of code in Java
what is a local variable?
a local variable is a variable that is declared within the body of a method directly, outside of any other code blocks such as conditionals or loops.
a variable that can only be used within a specific scope.
why use local variables?
local variables use less memory
remains the same (other parts of the program can’t change the variable)
reuse variable names
what symbols are the arithmetic operators?
+,-,*,/,%
what is this operator %
this is the modulus operator or remainder operator
example 7%5 = 2
is order of operations followed in Java
yes, order of operations is performed the same as in basic math
what is integer division
integer division is when the final result will be an integer, any remainder will be lost.
ex.
i = 5/2
i = 2
what is a compound assignment operator?
a compound assignment operator is when you want to add a number to another number that is already stored in a variable, then assign the result back into the variable.
ex.
int count = 0;
count = count + 10;
what are all of the compound assignment operators?
+= - adds and assigns
-= - subtracts and assigns
*= - multiple and assigns
/= - divides and assigns
%= - modulo and assigns