Lasso Soft Inc. > Home

[ file->forEach ]


The [file->forEach] method takes a block of code that will be executed for each character or line in the file the [file] object refers to depending on which the get mode is set to. Inside the block you can access the current line using the special local variable #1 which will be a byte stream containing a line from the file.

  • Syntax
local(f) = file(...)
#f->forEach => {
  • Intermediate

Display a Lasso code file with line numbers

The code below will output the contents of a Lasso source file as an ordered list. The default get mode is to read characters at a time instead of lines, so it is necessary for me to set the get mode specifically to reading lines in the [file] creator method below.


local(my_file) = file('index.lasso', io_file_o_rdonly, file_modeline)
handle => {#my_file->close}
#my_file->forEachLine => {^
    '<li>' + string(#1)->encodehtml + '</li>'


  1. <?=
  2. library_once('/_config/conf.lasso')
  3. date
  4. ?>

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft