Monday, 28 March 2016

Next Gen 17/03/16 Coding Loops

The main point of coding this week was to show all of the four loops in coding their purpose and how they operate (another piece to use into a ever expanding dictionary of code to use). The main point of these loops is to repeat code until conditions are met (think of them as constant if statements).

1. While loops: The way these work is that while a condition is met, the code will continually loop.
2. Do While Loop: This follows the pattern of the while loop, but the condition is tested at the end of the code body. Meaning the code will run at least once before stopping. These be useful for mechanics like temporary barriers (say until you get a certain item or enough resources).
3. For Loop: This loop has the same function as the while loop however it uses a different syntex. It uses three separate sections for information in the loop (declaring variables, the conditional, increase/decrease). This can be used as a more precise way of using code to add multiple variables for one final result.
4. For Each Loop: This loop is used to go through arrays of code (strings) to test the items in the array, like looking through a list. This application is useful for having enemies spawn in certain locations across a map, without getting to close to some objects or the player.

The next step is to use these in coding to test and the use them when needed. These pieces of code though so far have been the hardest to use because (for me) it interferers with the rest of the coding.


No comments:

Post a Comment