← Back to Lua Course | Chapter 1: Introduction | Lesson 7 of 7

Statements और Chunks

एक Lua file एक chunk है, statements की एक list जिसे semicolons या किसी special ending की ज़रूरत नहीं।

In this page:

  1. Statements और Chunks

Statements और Chunks

एक chunk statements की कोई भी sequence है और वह unit है जिसे Lua compile और run करता है, या तो एक file या एक string। Statements whitespace से separated होते हैं, और semicolons optional हैं। main chunk खुद एक function है जो command-line arguments को varargs की तरह receive करता है।

Note: जब आपको अपने local variables वाला एक block चाहिए तो code को do ... end में wrap करें।

उदाहरण: Statements and chunks

lua
local a = 1; local b = 2
print(a + b)

do
  local hidden = "inside block"
  print(hidden)
end

print(select("#", ...))
print(load("return 6 * 7")())

-- Output:
-- 3
-- inside block
-- 0
-- 42
{# 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. habit से हर line के अंत में एक semicolon लगाना और सोचना कि यह required है
  2. एक line को parenthesis से शुरू करना और गलती से पिछला statement continue करना
  3. एक block के बाद end भूल जाना
चैप्टर सारांश
  • एक chunk statements की एक sequence है
  • Semicolons optional हैं
  • main chunk arguments ... की तरह receive करता है
  • do ... end एक explicit block बनाता है
🔒

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.