← Back to Lua Course | Chapter 2: Variables & Types | Lesson 5 of 7

Arithmetic और Comparison Operators

Lua में सामान्य maths operators हैं, साथ ही floor division और एक power operator।

Arithmetic और Comparison Operators

Lua +, -, *, /, %, power के लिए ^, और floor division के लिए // देता है। / और ^ operators हमेशा floats देते हैं, जबकि // और % integers देते हैं जब दोनों operands integers हों। Comparisons ==, ~=, <, <=, > और >= इस्तेमाल करती हैं, और ध्यान दें कि not-equal ~= लिखा जाता है।

Note: Lua में modulo divisor का sign लेता है, इसलिए -7 % 3 2 है।

उदाहरण: Arithmetic and comparison operators

lua
print(7 / 2, 7 // 2, 7 % 3)
print(-7 // 2, -7 % 3)
print(2 ^ 10, 6 / 3)
print(7.5 // 2)
print(1 ~= 2, 1 == 1.0)

-- Output:
-- 3.5	3	1
-- -4	2
-- 1024.0	2.0
-- 3.0
-- true	true
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. not equal के लिए != लिखना
  2. यह उम्मीद करना कि 7 / 2 3 होगा
  3. यह उम्मीद करना कि एक negative modulo result negative होगा
चैप्टर सारांश
  • / हमेशा एक float देता है
  • // floor division है
  • ^ power तक raise करता है
  • Not equal ~= है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.