Oct 032011

When programming, have you ever found yourself doing the same thing over and over again, with only a slight modification each time?  That’s where loops come in handy.  There are many different kinds of loops.  The “for” loop is perhaps the most basic, so let’s start there.

Suppose I want to count from 1 to 100, counting by ones.  I can do this in the following way, using javascript.

for (i = 0; i >= 100, i++) {
     alert (i);

Let’s break this down.  In this “for” loop, there are 5 distinct parts.  The iterator, which we called “i”; the starting point, which we said would be “0”; the stopping point, which we said was 100; the amount to increase by each time, which was ++.  ++ in programming means “increase by one”; finally, inside the curly brackets { }, we told the loop what to do each time.  In this case, we said, “alert the iteration I’m currently on.”

These basic elements are the same for most languages, though in some they are not all required.  For loops in php are very similar to for loops in javascript.  In PHP, I would write a for loop to print 1 to 100 on the screen in html using the following loop.

for (i = 0; i < 101; i++) {
     print i.”</br>”

in lua (the language used for the CoronaSDK), the for loop looks a little different, but basically the same.  Consider the following:

for i = 0, 100 do
    print (i)

notice that I didn’t have to write “increase by 1” each time?  That’s because, by default, the loop structure assumes that you want to increment by 1 each time, so you only have to write the incrementation when you want to use a different value.  For example, increasing by 5 each time would look like this:

for i = 0, 100, 5 do
    print (i)

Iterating over arrays

The above  is fine and dandy if you want to do something a pre-determined amount of times.  What if you wanted to loop through each item in an array and do something to it?  There are several ways of doing this.  Let’s start with a “foreach” loop in php.  A foreach loop simply says, “for each item in X array, do something.”  For example, suppose you had the following array:

$classNames = array(“Peter”,”Ammon”,”Robert”,”Jen”,”Mike”,”Pam”,”Vera”);

Let’s suppose you wanted to add each of those folks to a list.  You could use a foreach loop to: (a) print the person’s name, and (b) enter a carriage return (i.e., go to the next line).  It would look like this:

foreach ($classNames as $name) {

     print $name.”<br/>;


pretty easy, no?  Let’s break it down.

  1. The “foreach” command indicates that the loop needs to do whatever is between the curly brackets to each item in the array.
  2. $classNames indicates the entire array
  3. $name is a variable I made up to represent a single entry as you are working on it.  This is the variable you will likely use the most inside of the loop (i.e. it’s the variable you’ll be operating on).

What if you had an associative array and you wanted to use the key as well as the value?  For example, suppose our array looked like this:

$classBirthdays = array(

“Peter” => “4 April 1978”,

“Ammon” => “23 November 1956”,

“Jen” => “2 November 1973”


Our loop would then look like this

How might you use a for loop in your project?

 Posted by at 7:43 am
Sep 302011

Jonathan Beebee explains classes (or at least, their equivalent) in CoronaSDK.  This is a very quick tutorial and well worth the time it takes to learn about modularizing your code.  See the tutorial at: http://blog.anscamobile.com/2011/09/tutorial-modular-classes-in-corona/

 Posted by at 6:11 am
Sep 292011

Some notes from today’s lesson (in 760) on Git.

    • Repository: Your main main main set of files
    • Clone: A local copy of a project you might be working on
    • Master Branch: Called “master” by default (but you can change the name).  Subdirectories from a master directory.
    • Commit:  Take what I’ve just been working on and submit it to the database.  Creates an entry in history.
    • Checkout: .git folder has all working files.  When you commit to a branch, you “checkout.”  Changes your working file directory.
    • Merge:  combining committed changes.  You’re not getting rid of the other branch when this happens. You’re creating a new commit.
    • add: “git add {filename}”  Looks for changes and puts those on a virtual stage.  Those changes will be included in the next commit.
    • remote: default is called “origin.”
      • fetch: repository –> local
      • push:  local –> repository
      • pull: I have some changes, let’s do a 2-way sync. local <–> repository

NOTES from Ben:

configuration options

git config –global user.name “your name”

git config –global user.email “your email”

git config –global core.editor “your editor”


Start using git on a directory

git init git directory


Add files to be included in Next Commit

git add .


Get status

git status



git commit -m “commit name”


Clone Repository

git clone url


See differences

git diff



list branches – git branch

create branch – git branch (branchname)

switch to branch –  git checkout branchname

delete branch – git branch -d branchname

delete branch – git branch -D branchname



list remotes – git remote

add new remote – git remote add alias url

get from remote – git fetch alias

push to remote – git push alias branch




 Posted by at 9:35 am
Sep 262011

A discussion I had today reminded me of President Samuelson’s opening devotional.  I really liked the words of wisdom he shared and I think they’re appropriate, especially as they relate to a project-based class like this.  I would highly recommend you read, “Appropriate Zeal,” even if you already listened to the talk.  It helps give perspective, methinks.

 Posted by at 11:24 am
Sep 262011

One of the aims of a BYU education is lifelong learning.  In this course, I hope to help you establish the patterns of finding and utilizing the many resources available to you that will enable you to continue learning your chosen technology long after this course ends.  D&C 130 talks a little bit about the importance of this in two places.  D&C 88:118 reads:

118 And as all have not faith, seek ye diligently and teach one another words of wisdom; yea, seek ye out of the best books words of wisdom; seek learning, even by study and also by faith.

And then 109:7 says the same thing.

7 And as all have not faith, seek ye diligently and teach one another words of wisdom; yea, seek ye out of the best books words of wisdom, seek learning even by study and also by faith;

So, what I get out of this is that there are books, and there are better books, and there are best books.  BYU has done a lot to help us have access to some of the best books.  Let’s make really good use of them, shall we?

 Posted by at 8:58 am
Mar 162011

As I’ve collaborated with some of my colleagues, I’ve thought recently about a scripture that may be used ad nauseum in education, but is nonetheless very important.  The Lord tells us in Doctrine and Covenants, section 88, verse 118:

And as all have not afaith, seek ye diligently and bteach one another words of cwisdom; yea, seek ye out of the best dbooks words of wisdom; seek learning, even by study and also by faith.

There are good ways to use our time and there are better ways. Seeking learning of the best books, for example, is better than spending an hour reading the vitriol-laden boards on a news article about my local sports team (fun as it may be).  With the advent of audio books, it has become even easier to do this than formerly.

 Posted by at 9:48 am
Mar 072011

I wanted to share something I read in the latest Ensign (March, 2011).  This comes from a talk by Pres. Joseph Field Smith in 1953.  He states,

“So I say to you, and all the members of the Church for that matter, do not let your understanding rest upon one verse…but search the scriptures that you may not be deceived by false theories and practices and doctrines so prevalent in the world today. If you will do this, if you will have in your hearts the guidance of the Spirit of the Lord which every member of the Church has a right to have, the companionship of the Holy Gost, you will not be led astray …and you will have the spirit of discernment that you may understand”

So often we find ourselves talking about our “favorite scripture.” But the truth is that this is something that should be changing all the time as we continually study. A single scripture will not provide us with the understanding that we need to adequately understand the Lord’s prompting and discern good from evil.

 Posted by at 9:21 am
Mar 022011

When I have shared spiritual thoughts in this class, it has always been with a deliberate connection to programming in mind. While that is fine and dandy and can sometimes be fun, it can also sometimes be a stretch. The university devotional this week reminded me that teaching by the Spirit and with the scriptures is just that–helping others to feel and recognize the Spirit. The spiritual thought needn’t be connected to programming, but is meant to simply uplift. With that in mind, I’m reminded of Christ’s exortation to let our light so shine.

Matthew 5:16
16Let your alight so shine before men, that they may see your good bworks, and cglorify your Father which is in heaven.

 Posted by at 10:25 am
Feb 232011

It’s right there in plain sight in the old testament (Isaiah 28:10)

10. For precept must be upon precept, aprecept upon precept; line upon line, line upon line; here a little, and there a little:

Notice the semicolon at the end of the “line?” 😉

 Posted by at 9:57 am