Difference between revisions of "X file:lines"

From GiderosMobile
(Created page with "__NOTOC__ <languages /> '''<translate>Available since</translate>:''' Gideros 2011.6<br/> '''<translate>Class</translate>:''' file<br/> === <transl...")
 
(redone)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
<languages />
+
'''Available since:''' Gideros 2011.6<br/>
'''<translate>Available since</translate>:''' Gideros 2011.6<br/>
+
'''Class:''' [[file|file]]<br/>
'''<translate>Class</translate>:''' [[Special:MyLanguage/file|file]]<br/>
 
=== <translate>Description</translate> ===
 
<translate>Returns an iterator function that, each time it is called, returns a new line from the file. Therefore, the construction
 
  
    ''for line in file:lines() do body end''
+
=== Description ===
 +
Returns an iterator function that, each time it is called, returns a new line from the file.
 +
<source lang="lua">
 +
(function) = file:lines()
 +
</source>
 +
 
 +
Unlike '''[[io.lines]]''', this function does not close the file when the loop ends.
  
will iterate over all lines of the file. (Unlike io.lines, this function does not close the file when the loop ends.)</translate>
+
=== Return values ===
 +
'''Returns''' (function) iterator function<br/>
 +
 
 +
=== Example ===
 +
'''To iterate over all lines of a file'''
 
<source lang="lua">
 
<source lang="lua">
(function) = file:lines()
+
for line in file:lines() do
 +
--body
 +
end
 
</source>
 
</source>
=== <translate>Return values</translate> ===
 
'''<translate>Returns</translate>''' (function) <translate>iterator function</translate><br/>
 
  
 
{{File}}
 
{{File}}

Revision as of 05:18, 7 December 2020

Available since: Gideros 2011.6
Class: file

Description

Returns an iterator function that, each time it is called, returns a new line from the file.

(function) = file:lines()

Unlike io.lines, this function does not close the file when the loop ends.

Return values

Returns (function) iterator function

Example

To iterate over all lines of a file

for line in file:lines() do
	--body
end