Intro. to Programming Workshop - 2

Welcome back to the Intro. to Programming Workshops! This week's workshop will focus on loops!
Starting from this week, the first half of each workshop will include a demonstration of how the current week's content can be applied to create a game! The source code for this game will progressively expand and develop each week as more content is covered. It will also be available to download in next week's workshop blog post.

Resources

  • Questions for Week 3: http://docdroid.net/ux9e
  • If you have any queries or comments, feel free to send me an email at: undergrad@suits.org.au

Summary

The while-loop Syntax
while( <condition> ){  
    <code_to_loop>
}

The Good
+ Simple syntax
+ Convenient if number of loops is not fixed

The Bad
- Easy to forget about updating to loop-condition

The for-loop Syntax
for( <initialization> ; <condition> ; <update> ){  
    <code_to_loop>
}

The Good
+ Clear and organised syntax for nesting loops
+ Variables declared in <initialization> are removed when exiting loop

The Bad
- May look a little messy if number of loops is not fixed