1/30
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
a situation when we need to execute a block of code several number of times,
loops
a control structure that allows you to repeat a task a certain number of times.
while loop
syntax of while loop:
while(Boolean_expression) {
// do this
}
is similar to a while loop, except that it is guaranteed to execute at least one time.
do - while loop
syntax of do-while loop:
do {
// do this
} while(Boolean_expression);
a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
for loop
syntax of for loop:
for(variable initialization; Boolean_expression; update){
// do this
}
is mainly used for Arrays.
enhanced for loop
syntax of enhanced for loop
for(declaration : expression){
//Statements
}
a type compatible with the elements of the array you are accessing. The variable will be available within the for block and its value would be the same as the current array element.
Declaration
This evaluates to the array you need to loop through
can be an array variable method call that returns an array.
expression
used to break the loop.
break
make the loop jump to the next iteration.
continue
allow you to make a decision, based upon the result of a condition.
decision-making
types of decision making in java:
if statement
switch statement
java looping mechanisms
for loop
do while
while
consists of a Boolean expression followed by one or more statements.
if statement
executes when the Boolean expression is false.
if else
In case that the first condition returns false
else if
is not required but a good thing to do if you need to handle possibilities
else
you can use one if or else if statement inside another if or else if statement.
if your code has multiple conditions to achieve
nested if
selects one of many code blocks to be executed.
switch statement
used to declare the beginning of the statement followed with the variable or expression to be validated.
switch
used to declare the possible value that the expression might have.
case
used to declare the action or code block to run if there is no cases satisfied. Also not required.
default
These represent serious problems that a typical application should not attempt to handle.
error
These indicate conditions that a program might try to catch and handle. They represent problems that can occur during the execution of the program, often due to issues within the code itself or external factors.
exceptions
These exceptions must be either caught using a try-catch block or declared in the method signature using the throws keyword.
checked exceptions
Also known as runtime exceptions, these do not need to be explicitly caught or declared. They typically result from programming errors,
unchecked exceptions
allows you to create a custom error. It can be used together with an exception type.
throw statement
lets you execute code, after try...catch, regardless of the result.
finally statement