Tuesday, October 6, 2015

Programming with Java statements


 Understanding Assignment Statements
•An assignment statement sets a value within a variable
•All assignment are considered to be expression statements
•Expressions in Java are anything that has a value

•Typically, expressions evaluate to primitive types
•Commonly known simply as assignment statements, are designed to assign values to variables and must be terminated with a semicolon
Variable = value;
•On the left is the variable that will be associated with the memory and type necessary to store the value. On the right is a literal value.
The if conditional Statement
•The if statement is designed to conditionally execute a statement or conditionally decide between a choice of statements.will execute only one statement upon the condition, unless braces are supplied. Braces allow for multiple enclosed statements to be executed. This group of statements is also known as a block,evaluate to a boolean value,The else clause is optional and may be omitted
The if-then conditional Statement
•The if-then statement is used when multiple conditions need to flow through a decision-based scenario
The if-then-else conditional Statement
•The main difference is that the code will fall through to the final stand-alone else when the expression fails to return true for any condition
The switch conditional Statement
•It is used to match the value from a switch statement expression against a value associated with a case keyword. Once matched, the enclosed statements associated with the matching case value are executed, unless a break statement is encountered
. Understanding Iteration Statements
•Iteration statements are used when there is a need to iterate through pieces of code
•Iteration statements include for loop, enhanced for loop, and the while and do-while statements.
The for loop Iteration Statement
•The expression within the for loop must be evaluated to a boolean value
•The iteration, also known as the update part, provides the mechanism that will allow the iteration to occur
The enhanced for loop Iteration Statement
•It is used to iterate through an array, a collection, or an object that implements the interface iterable.
•It is also commonly known as the for each loop
The while Iteration Statement
•This loop evaluates an expression and executes the loop body only if the expression evaluates to true
The do-while Iteration Statement
•It is very similar to the while loop, except that it always executes the body at least once
4. Understanding Transfer of Control Statements
•Transfer of control statements include the break, continue and return statements




No comments:

Post a Comment