Jump to content




Lua Basics -- Variable Scope, Code Blocks and Control Structures

lua

  • You cannot reply to this topic
No replies to this topic

#1 surferpup

  • Members
  • 286 posts
  • LocationUnited States

Posted 14 January 2014 - 10:21 PM

This tutorial is now complete. Post suggestions for change in comments below.

Tutorial: Lua Basics -- Variable Scope, Code Blocks and Control Structures

As a newcomer to Lua (but not to programming in general), I needed to wrap my brain around a few concepts that are specific to the Lua way of doing things. One of the first things I studied was issues of variable scope, how Lua defines blocks of code, and what control structures were available to me in Lua.

This tutorial is offered as a topic in the Ask A Pro series of tutorials requested by Lyqyd (see Ask A Pro Renewal Project (and How You Can Help!)). Specifically, it will introduce the concept of Global and Local Variables, Code Blocks and Control Structures in the language. Every programmer new to Lua (or every new programmer) needs to tackle these topics early on in the learning of the language. Keywords covered in this tutorial include:
  • local
  • do
  • end
  • if
  • then
  • else
  • elseif
  • while
  • repeat
  • until
  • for
Pre-Requisites

Variable Scope and Code Blocks

Control Structures

Further Reading and Sources

If this tutorial was helpful, let me know. If it was confusing in sections, let me know and I will rework them. The topics I covered should give a newcomer to Lua sufficient information to use the language, especially if they have experience in other languages. I hope it is also useful for brand new programmers as well.

Edited by surferpup, 20 January 2014 - 05:13 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users