Advertisement
Guest User

For Loops

a guest
Jun 28th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. /** A for loop is like a while loop. */
  2.  
  3.     for(...) {
  4.         // execute until condition is false
  5.     }
  6.    
  7. /** Except for loop declarations consists of 3 parts. */
  8.  
  9.     for(declaration; condition; post-execution) {
  10.         // execute until condition is false
  11.     }
  12.    
  13. /** This is because for loops maintain their own variable. */
  14.  
  15.     for(int i = 0; i < 10; ...) {
  16.        
  17.     }
  18.  
  19. /**
  20. The last section is used to execute code which helps reach the condition.
  21.  
  22. In this case, we want 0 to increase.
  23. */
  24.  
  25.     for(int i = 0; i < 10; i++) {
  26.        
  27.     }
  28.    
  29. /** This is handy for "looping over arrays" to set values. */
  30.  
  31.     int[] numbers = new int[5];
  32.    
  33.     for(int i = 0; i < numbers.length; i++) {
  34.         numbers[i] = 10;
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement