2/26/2024 0 Comments Java for loop incremeantAfter all, it looks like we increment the variable and store the result. ![]() The following list covers quite a few examples-albeit some are silly: i = i + 1 ĭespite all the options above, I’d never thought to try i = i++, yet it makes a lot of sense. Java Increment OperatorsĪs I mentioned already, there are a lot of ways to increment a variable in Java. Unfortunately, my push for self-expression can sometimes result in mangled syntax like: int i = 0 Įvery time I see something like this I feel like I move one step closer to overcoming the curse of knowledge. Of course, once I think they’ve grasped the concept, I usually resort to shorthand like i++ and i += 1. For example, I tend to teach i = i + 1 first because it trips students up who haven’t recognized that the equal sign is really the assignment operator. Every once in a while I’ll even throw in some recursion to shake things up, but you’ll never catch me dead using a do while loop.Īt any rate, this mentality shows up when I increment variables as well. If I’m feeling good, I might even show off a for each loop. ![]() Sometimes I’ll use a for loop while other times I’ll use a while loop. For instance, it’s not uncommon for me to share solutions to looping problems using a different loop syntax each time. To aid in that message, I like to switch up my syntax every now and then. After all, I often tell my students that there are many ways to solve a problem. ![]() Perhaps this odd bit of code was my fault. In my recent attempt to teach loops, I stumbled up a student solution that had the following while loop syntax: int i = 0 However, as I continue to teach, I find that students always come up with creative ways to stretch the language. As someone who has written a bit of Java learning material, I consider myself at the very least proficient in the language.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |