= 18 THEN PRINT “You Qualify” ELSE PRINT “You do not qualify” END IF"> = 18 THEN PRINT “You Qualify” ELSE PRINT “You do not qualify” END IF">

Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Coding Design Tools Rachel Gauci

2 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.)

3 Example- Pseudocode Pseudocode’s used to point out the actions in your script. How is this done? You write your script in an informal way, leaving out ; () {} etc. then you put the main words in capitals/ bold making them stand out. Ideally we want to write what we want a particular part of code to look like E.G. #pragma strict var age= 22; function Start() { if (age >= 18) { Debug.Log ("You Qualify"); } else { Debug.Log("You do not qualify"); } } function Update() { } IF AGE >= 18 THEN PRINT “You Qualify” ELSE PRINT “You do not qualify” END IF

4 More Pseudocode https://www.khanacademy.org/com puting/cs/programming/good- practices/p/pseudo-code this is for drawings and in its simplest form explains pseudo code and why we use it. However this demonstration is not how I want it set out. http://myweb.lmu.edu/dondi/share/i ntro/pseudocode2js-v02.pdf Set total to zero Set grade counter to one WHILE grade counter is less than or equal to ten Input the next grade ADD the grade into the total Set the class average to the total divided by ten PRINT class average. START Program Enter two numbers A, B Add the numbers together PRINT sum END program

5 Example- IPO charts #pragma strict var age= 22; function Start() { if (age >= 18) { Debug.Log ("You Qualify"); } else { Debug.Log("You do not qualify"); } } function Update() { } INPUTPROCESSOUTPUT AgeUser puts in age -- it is determined whether the person is 18 or > < Results whether “You Qualify” or “You do not Qualify”

6 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 }

7 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.

8 Design solution 1. Create an IPO chart 2. Create a Pseudocode INPUTPROCESSOUTPUT NumberUsing input (variable) loop over the input until the condition is satisfied (<=) Loop “Count” input BEGIN Declare input FOR start variable = 1, variable <= input, Add 1 PRINT "Count:” input + 1 END

9 Code solution #pragma strict var x= 12; function Start () { for (var i = 1; i <= x; i++) { Debug.Log ("Count:" + i); } } function Update () { }

10

11 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.

12 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 }


Download ppt "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."

Similar presentations


Ads by Google