"لوا (پروگرامنگ زبان)" کے نسخوں کے درمیان فرق

حذف شدہ مندرجات اضافہ شدہ مندرجات
اضافہ مواد
←‏مثالیں: incomplete
سطر 50:
end
</syntaxhighlight>
 
===لوپ===
لوا زبان میں چار قسم کے لوپس ہیں:
* while loop
* repeat loop
* for loop
* اور عام لوپ
 
وہائل لوپ (while loop) کا سنٹیکس اس طرح ہے:
<syntaxhighlight lang="lua">
local condition = true
while condition do
--Statements
end
</syntaxhighlight>
 
اور <tt>repeat</tt> loop:
<syntaxhighlight lang="lua">
local condition = false
repeat
--Statements
until condition
</syntaxhighlight>
executes the loop body at least once, and would keep looping until <tt>cond</tt> becomes true.
 
اور <tt>for</tt> loop:
<syntaxhighlight lang="lua">
for index = 1,5 do
print(index)
end
</syntaxhighlight>
would repeat the loop body 5 times, outputting the numbers 1 through 5 inclusive.
 
<tt>for</tt> loop کی دوسری شکل:
<syntaxhighlight lang="lua">
local start,finish,delta = 10,1,-1 --delta may be negative, allowing the for loop to count down or up.
for index = start,finish,delta do
print(index)
end
</syntaxhighlight>
 
جنرک <tt>for</tt> loop:
<syntaxhighlight lang="lua">
for key,value in pairs(_G) do
print(key,value)
end
</syntaxhighlight>
would iterate over the table <tt>_G</tt> using the standard iterator function <tt>pairs</tt>, until it returns <tt>nil</tt>.
 
== حوالہ جات ==