Professional Documents
Culture Documents
Adrian Pearce
Adrian Pearce
Outline
Introduction
Iteration in games
Outline
Introduction
Iteration in games
Iteration
In this lecture, we will investigate how loops, operators and functions can be used to iteratively solve problems.
Outline
Introduction
Iteration in games
10
11
Pseudocode
Set initial values for the year, population and growth rate FOR the number of years to be simulated Calculate and append next value to year vector Calculate and append next value to population vector Plot the results
12
Pseudocode
Set initial values for the year, population and growth rate FOR the number of years to be simulated Calculate and append next value to year vector Calculate and append next value to population vector Plot the results
Activity
Have a go at writing the code to compute the world population from 1950 to 1999, given that the population at 1950 was 2.56 109 (P1 = 2.56 109 , t1 = 1950) and the growth rate g = 0.018.
13
Pseudocode
Set initial values for the year, population and growth rate WHILE the population is less than the desired population Calculate and append next value to year vector Calculate and append next value to population vector Plot the results
14
Pseudocode
Set initial values for the year, population and growth rate WHILE the population is less than the desired population Calculate and append next value to year vector Calculate and append next value to population vector Plot the results
Activity
Have a go at writing the code to compute the year that the world population will reach 1 1012 , given that the population at 1950 was 2.56 109 (P1 = 2.56 109 , t1 = 1950) and the growth rate g = 0.018.
15
Outline
Introduction
Iteration in games
16
17
Next Lecture
Games
18