Assignment Statement Adalah

Posted on by Zura

By Doug Lowe

An assignment statement in Java uses the assignment operator (=) to assign the result of an expression to a variable. In its simplest form, you code it like this:

variable = expression;

For example:

int a = (b * c) / 4;

A compound assignment operator is an operator that performs a calculation and an assignment at the same time. All Java binary arithmetic operators (that is, the ones that work on two operands) have equivalent compound assignment operators:

OperatorDescription
+=Addition and assignment
-=Subtraction and assignment
*=Multiplication and assignment
/=Division and assignment
%=Remainder and assignment

For example, the statement

a += 10;

is equivalent to

a = a + 10;

Technically, an assignment is an expression, not a statement. Thus, a = 5 is an assignment expression, not an assignment statement. It becomes an assignment statement only when you add a semicolon to the end.

An assignment expression has a return value just as any other expression does; the return value is the value that’s assigned to the variable. For example, the return value of the expression a = 5 is 5. This allows you to create some interesting, but ill-advised, expressions by using assignment expressions in the middle of other expressions. For example:

int a; int b; a = (b = 3) * 2; // a is 6, b is 3

Using assignment operators in the middle of an expression can make the expression harder to understand, so it’s not recommend that.

Assignment Statement



Evaluates an expression and stores the result in a variable.
Valid:in a DATA step
Category:Action
Type:Executable


Arguments

variable

names a new or existing variable.

Range:Variable can be a variable name, array reference, or SUBSTR function.
Tip: Variables that are created by the Assignment statement are not automatically retained.
expression

is any SAS expression.

Tip:expression can contain the variable that is used on the left side of the equal sign. When a variable appears on both sides of a statement, the original value on the right side is used to evaluate the expression, and the result is stored in the variable on the left side of the equal sign. For more information, see Expressions in SAS Language Reference: Concepts.

Assignment statements evaluate the expression on the right side of the equal sign and store the result in the variable that is specified on the left side of the equal sign.

These assignment statements use different types of expressions:

  • name='Amanda Jones';
  • WholeName='Ms. '||name;
  • a=a+b;

Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.

Categories: 1

0 Replies to “Assignment Statement Adalah”

Leave a comment

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *