Coding Design
Tools
Rachel Gauci
Task: Counting On
Create a program that will print out a sequence of
numbers from "1" to a "number entered”.
Decision’s need to be made before moving onto designing…
1. What does the task want?
2. What type of script would best fit the requirements (e.g.
IF ELSE statement, FOR/WHILE LOOPS etc.)
LOOPS
FOR LOOPS- the loop is repeated a "specific" number of times,
determined by the program or the user. The loop "counts" the number of
times the body will be executed. This loop is a good choice when the
number of repetitions is known, or can be supplied by the user.
(set initial variable; condition;
action on the variable)
for (var i : int = 0 ;
i < numEnemies ; i++)
While Loops: The loop must repeat until a certain "condition" is
met. If the "condition" is FALSE at the beginning of the loop, the loop is
never executed. The "condition" may be determined by the user at the
keyboard. The "condition" may be a numeric or an alphanumeric
entry. This is a good, solid looping process with applications to
numerous situations.
while (condition/expression) {
Statement/s to be executed if expression is true }
The for loop is used to repeat a section of code known number of times. Sometimes
it is the computer that knows how many times, not you, but it is still known. Some
examples:
Unknown number of times:
• "Ask the User to Guess a pre-determined number between 1 and 100".
You have no way of knowing how many guesses it will take.
• "Randomly look in an array for a given value." You have no way of
knowing how many tries it will take to find the actual value.
Note: this is a made-up example, because you would never randomly look into an array to find a value. You
would always start at the front of the array and look one element at a time until you found the item or got to
the end of the array.
Known number of times:
• Compute the average grade of the class. While you (the programmer)
might not know how many grades exist in the class, the computer will
know. Usually this is accomplished by using the "length" function on an
array.
• Print the odd numbers from 1 to 1001.
• Search a list (array) of numbers for the biggest grade. Again, the
computer "knows" how many grades there are, so a for loop is
appropriate.
Design solution
1. Create an IPO chart
INPUT
PROCESS
OUTPUT
Number
Using input (variable) loop over the input
until the condition is satisfied (<=)
Loop “Count” input
2. Create a Pseudocode
BEGIN
Declare input
FOR start variable = 1, variable <= input, Add 1
PRINT "Count:” input + 1
END
Code solution
#pragma strict
var x= 12;
function Start () {
for (var i = 1; i <= x; i++) {
Debug.Log ("Count:" + i);
}
}
function Update () {
}
How can we test the user’s input?
In Unity, when you create a variable in your script (outside
the LOOP statement) you give it an initial value. When
you look at your script in the inspector view, it will give
you the opportunity to edit your variable and press play to
see the result.
If, Else if
if statement - executes some code only if a specified condition is true
if...else statement - executes some code if a condition is true and another
code if the condition is false
if...elseif....else statement - selects one of several blocks of code to be
executed
If (condition) {
statement
}
Else if (other condition) {
statement
}
© Copyright 2026 Paperzz