Showing posts with label Basic. Show all posts
Showing posts with label Basic. Show all posts

Saturday, November 15, 2014

Understanding Java Looping using FOR

FOR function used for do some similar command with certain limited count number. The basic structure of FOR is like this:

for(START, END, INCREMENT){
       // some command
}

So, if you want to show number 1-10, you just create code like this:

for(int i=0;i<=10;i++){
     System.out.print(i);
}

explanation:
int i = 0 is set up the first number
i<= 10 is a limited number. Symbol <= means i value smaller or same than 10
i++ is for increment first number. If you want to decrement function, you can write as i--