Write a sketch that prints the numbers in the given array and at the end prints the total of the sum of the numbersin the array. Here is the array to use:
var nums = [42,23,5,2,3,8,10,12,61,95];
Use text() to display the output on screen.
Do this two ways in the same sketch, outputting to two areas on the screen. One with a while loop and one with a for loop.
Output is to look like:
While Loop
Number 42
Number 23
…
Total X
For Loop
Number 42
Number 23
…
Total X
To get the heading to appear above the numbers “easily”, I did this:
text(“While Loop”, 200, 200 – textHeight());
Go back to Arrays 1