code :
========================================================================
public class whileloop {
public static void main (String args[]) //Line 5
{
int banana = 0;
while (banana<10) //Line 9
{
System.out.println(banana);
banana++; //Line 12
}
}
}
public static void main (String args[]) //Line 5
{
int banana = 0;
while (banana<10) //Line 9
{
System.out.println(banana);
banana++; //Line 12
}
}
}
========================================================================
Then as usually I want you guys to type in your program to your Text Editor (I really hope you guys are using Eclipse so that you guys can understand my explanation easier, Learn how to download Eclipse in Part 3 ) .Then run your program to check the results. I'm absolutely sure the output of the program is going to be look exactly like this picture below.
See ? It is a lot of easier than type the "System.out.println( );" keyword ten times.It will save you a bunch of time which is gonna make you more productive.Actually there is a lot more of these kind of looping statements that will be very useful when you have reached the advance level of programming. But in this tutorial I will make this one clear first.
So as usual I'm going to explain to you guys each lines on the program above. But I'm not really going to explain each lines because I'm pretty sure you guys already feel familiar with some lines that I have explained in the couple of tutorials before.
Line 9 :
This is the most important syntax in the program above. This while loop declared that It will run the programs inside the brackets while the value of the variable is less than 10. I will give you guys a scheme of this program so that you guys can understand it easier below
So from the scheme above we can conclude that the while loop keep doing the syntax inside the curly brackets as long as the value inside the regular brackets is required. The reason why is this program only printing the value until number 9 is because the condition inside the regular brackets tells java that this looping has to be stopped if the variable's value has reached 9 (banana<10). I'm pretty sure that you guys have learn the less (<) and greater (>) sign in your school so I don't think I have to explain it anymore.
So that's it guys for now. Thank you guys for visiting my blog, hope you guys enjoy it and see you on the next tutorial. If you guys got something to be asked, please leave a comment below and thank you very much.
Then as usually I want you guys to type in your program to your Text Editor (I really hope you guys are using Eclipse so that you guys can understand my explanation easier, Learn how to download Eclipse in Part 3 ) .Then run your program to check the results. I'm absolutely sure the output of the program is going to be look exactly like this picture below.
See ? It is a lot of easier than type the "System.out.println( );" keyword ten times.It will save you a bunch of time which is gonna make you more productive.Actually there is a lot more of these kind of looping statements that will be very useful when you have reached the advance level of programming. But in this tutorial I will make this one clear first.
So as usual I'm going to explain to you guys each lines on the program above. But I'm not really going to explain each lines because I'm pretty sure you guys already feel familiar with some lines that I have explained in the couple of tutorials before.
Line 9 :
This is the most important syntax in the program above. This while loop declared that It will run the programs inside the brackets while the value of the variable is less than 10. I will give you guys a scheme of this program so that you guys can understand it easier below
So from the scheme above we can conclude that the while loop keep doing the syntax inside the curly brackets as long as the value inside the regular brackets is required. The reason why is this program only printing the value until number 9 is because the condition inside the regular brackets tells java that this looping has to be stopped if the variable's value has reached 9 (banana<10). I'm pretty sure that you guys have learn the less (<) and greater (>) sign in your school so I don't think I have to explain it anymore.
So that's it guys for now. Thank you guys for visiting my blog, hope you guys enjoy it and see you on the next tutorial. If you guys got something to be asked, please leave a comment below and thank you very much.
Greetings from Programmer !
No comments:
Post a Comment