- Lua Quick Start Guide
- Gabor Szauer
- 281字
- 2021-08-05 10:30:40
Operators
Operators such as addition +, string concatenation .., and even the assignment operator = have been used throughout this book. Let's take some time to cover in detail what operators are and how they work. Operators fall into one of the following categories:
- Arithmetic operators do math.
- Relational operators always return a Boolean value: true or false. Relational operators are used to compare the relationship between two things, for example, by checking whether one number is smaller than another number.
- Logical operators express complex relations such as and/or. For example, logical operations can be used to check whether a number is less than seven AND greater than two.
- Misc operators: All other operators, such as assignment, fall into this category.
Operators can be unary or binary. A unary operation works on only one operand. For example, the minus sign (-) is the unary negation operator. It returns the negative value of a number:
x = -7 -- negation operator applied to the constant 7
y = -x -- negation operator applied to the x variable
-- x: -7, y: 7
A binary operator on the other hand operates on two operands. The binary subtraction operator also uses the minus sign (-), but it is a completely different operator from its unary counterpart. An example of the binary subtraction operator would be:
x = 7 - 3 -- Operand 1 is the constant 7, Operand 2 is the constant 3
y = x - 1 -- Operand 1 is the variable x, Operand 2 is the constant 1
z = x - y -- Operand 1 is the variable x, Operand 2 is the variable y
Most operators will be binary, that is, they will work on two operands.
- Objective-C應用開發(fā)全程實錄
- 樂學Web編程:網(wǎng)站制作不神秘
- SQL Server 2016數(shù)據(jù)庫應用與開發(fā)
- 從Excel到Python:用Python輕松處理Excel數(shù)據(jù)(第2版)
- 全棧自動化測試實戰(zhàn):基于TestNG、HttpClient、Selenium和Appium
- jQuery炫酷應用實例集錦
- 基于ARM Cortex-M4F內核的MSP432 MCU開發(fā)實踐
- Unity 3D/2D移動開發(fā)實戰(zhàn)教程
- 零基礎輕松學C++:青少年趣味編程(全彩版)
- Anaconda數(shù)據(jù)科學實戰(zhàn)
- jQuery Mobile Web Development Essentials(Second Edition)
- PHP動態(tài)網(wǎng)站開發(fā)實踐教程
- Visual FoxPro程序設計習題及實驗指導
- Moodle 3.x Developer's Guide
- Leaflet.js Essentials