Download presentation
Presentation is loading. Please wait.
Published byRandell Shanon Wilkins Modified over 9 years ago
1
New Tools And Workshop Mod & For Loops
2
Modulo Calculates the remainder (remember long division?) % Examples: 7 % 3 10 % 2 2 % 3 evaluates to 1 evaluates to 0 evaluates to 2
3
Incrementing and Decrementing Often you want to increase or decrease an int value by 1 We’ve done it like this: int i = 5; i = i + 1;// now i has a value of 6 Java has a shortcut: int y = 5; y++;// now i has a value of 6 y--;// now i has a value of 5
4
For loops Often you want to repeatedly execute a piece of code Many uses Example: for(int i = 0; i < 10; i++){ System.out.println(i); } New Keyword! Parenthesis encompass the 3 conditions Curly braces encompass the code to be looped over
5
3 conditions of a for loop for(int i = 0; i < 10; i++){ System.out.println(i); } 1.declare and define a counter variable 2. boolean condition, checked every iteration 3. update counter variable every iteration
6
Let’s do some coding…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.