Advertisement
xFazz

study1

Oct 19th, 2020
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. 3. For loops
  2.  
  3. Going backwards in an array -> More than or equal to zero, decrement the variable, start array at length - 1
  4.  
  5. Nested for loops -> Everytime you have 2 for loops, the outer one is run once and the inner is run all the way through
  6.  
  7. 4. Loops
  8.  
  9. Array indexes account for zero
  10.  
  11. When finding out which index is greatest, use a for loop and compare the indexes
  12. int[] example = {5, 7, 3, 9, 20, 4};
  13.  
  14. void setup() {
  15. int maxIndex = 0;
  16. for (int i = 0; i < example.length; i++) {
  17. if (example[i] > example[maxIndex]) {
  18. maxIndex = i;
  19. }
  20. }
  21. }
  22.  
  23. void draw() {
  24.  
  25. }
  26.  
  27.  
  28. int[] example = {60, 90, 50, 30, 60, 100};
  29. int numPass = 0;
  30. int numFail = 0;
  31.  
  32. void setup() {
  33. int maxIndex = 0;
  34. for (int i = 0; i < example.length; i++) {
  35. if (example[i] >= 70) {
  36. numPass++;
  37. }
  38. else {
  39. numPass--;
  40. }
  41. }
  42. }
  43.  
  44. void draw() {
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement