Lesson 12: Making a Game; Advanced Commands



All right, to make real games, you need loops! Loops are portions of code that get executed again and again, usually incrementing a counter or checking to see if something changes. Once the exit conditions are met, the loop is exited. In APE, our looping statement is called WHILE.

WHILE (conditional_expression) statementlist

WHILE checks to see if conditional_expression is true. If so, it executes the statementlist. If not, it goes on to the next statement. The statementlist can be one statement, or a block of statements inside curly brackets (just like we did with IF). Here's an example:

counter = 0
while (counter < 10)
{
A[$counter$] = 1
counter = counter + 1
}


This sets A[0] through A[9] equal to 1. Once counter = 10, then the WHILE condition is no longer true, and the loop exits.

That's it for now! Have fun storming the castle!