سلام
ترتیب عملگرهای محاسباتی تویه پاسکال رو براساس اولویت اجرا می خواستم.
پاک با بیسیک قاطی پاتی کردم.:قهقهه:
Printable View
سلام
ترتیب عملگرهای محاسباتی تویه پاسکال رو براساس اولویت اجرا می خواستم.
پاک با بیسیک قاطی پاتی کردم.:قهقهه:
نباید فرقی داشته باشه! مشابهات را جایگزین کنید. تا اونجاکه با Qbasic مقایسه می کنم مشکلی نبوده.
In complex expressions, rules of precedence determine the order in which operations are performed.
Precedence of operators
Operators Precedence
@, not first (highest)
*, /, div, mod, and, shl, shr, as second
+, -, or, xor third
=, <>, <, >, <=, >=, in, is fourth (lowest)
An operator with higher precedence is evaluated before an operator with lower precedence, while operators of equal precedence associate to the left. Hence the expression
X + Y * Z
multiplies Y times Z, then adds X to the result; * is performed first, because is has a higher precedence than +. But
X - Y + Z
first subtracts Y from X, then adds Z to the result; - and + have the same precedence, so the operation on the left is performed first.
You can use parentheses to override these precedence rules. An expression within parentheses is evaluated first, then treated as a single operand. For example,
(X + Y) * Z
multiplies Z times the sum of X and Y.
Parentheses are sometimes needed in situations where, at first glance, they seem not to be. For example, consider the expression
X = Y or X = Z
The intended interpretation of this is obviously
(X = Y) or (X = Z)
Without parentheses, however, the compiler follows operator precedence rules and reads it as
(X = (Y or X)) = Z
which results in a compilation error unless Z is Boolean.
Parentheses often make code easier to write and to read, even when they are, strictly speaking, superfluous. Thus the first example could be written as
X + (Y * Z)
Here the parentheses are unnecessary (to the compiler), but they spare both programmer and reader from having to think about operator precedence.
این موضوع ربطی به زبان برنامه نویسی نداره ، اینها باید در زبانها رعایت بشن ، اینها قاعده کلی دارن که مربوط به ریاضی هست ، اگر این قانونها در هر زبانی متفاوت باشن ، موقع نوشتن الگوریتم باید بسته به نوع زبان ، الگوریتم رو تغییر داد !!نقل قول:
آیا با Visual Basic یکسان هستش یا نه؟
موفق باشید ...