Here is a simple example of for loop:
class ArithmeticProgression
{
public static void main (String[] args)
{
int sum = 0;
for (int i = 1; i <= 1000; i++)
{
sum = sum + i;
System.out.println(Integer.toString(sum));
}
}
}
Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!
How do you go about converting this code from for loop to while loop?
for(int i = 0; i < 10; i++) { // Code Body }
int i = 0; while(i < 10) { i++; // Code Body }
int sum = 0; int i = 1; while(i <= 1000) { sum = sum + i; i++; System.out.println(Integer.toString(sum)); }I hope that's what you were looking for and you have a better understanding of the two loops. Let us know if you require anything else
0 members, 0 guests, 0 anonymous users
Community Forum Software by IP.Board
Licensed to: Geeks to Go, Inc.