answersLogoWhite

0

Example in Java:

int total = 0;

int i = 1

while (i <= 10)

{

total += i;

i++;

}

System.out.println("The sum of the first ten numbers is " + total);

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Math & Arithmetic

What is the difference between while loop and for loop in matlab?

A while loop executes code inside the while block continuously until the said condition is not true. A for loop contains three parts. The first part is carried out prior to the for loop, the middle part is executed by the for loop until it is no longer true, and the final part is performed at the end of each go round of the loop.


C program find magic number less than 1000?

#define int main (void){/*Algorithm*/1. First Initialize the number that is Random no2. Using while loop if the person got it, then the loop stop if not the loop continues.}return(0);


What type of loop is For k equals 7 to maxValue?

A very poorly defined loop. By default the looping index increases. The loop, as described in the question will not terminate if "maxValue" is less than 7.


How to draw Flowchart to print prime numbers from 1 to 100 using while loop in c language?

Oh, dude, drawing a flowchart for printing prime numbers from 1 to 100 using a while loop in C? That's like asking me to explain quantum physics while juggling flaming torches. But hey, you basically start with a start symbol, then draw a decision box to check if a number is prime, and loop back until you reach 100. Just remember to add some arrows and shapes, and you're good to go!


Compare While with for Statements?

The while loop is the more general one because its loop condition is more flexible and can be more complicated than that of a for loop. The condition of a for loop is always the same and implicit in the construction. A for loop stops if there are no more elements in the collection to treat. For simple traversals or iterations over index ranges it is a good advice to use the for statement because it handles the iteration variable for you, so it is more secure than while where you have to handle the end of the iteration and the change of the iteration variable by yourself.

Related Questions

What is the time complexity of using a while loop inside a for loop?

The time complexity of using a while loop inside a for loop is O(nm), where n is the number of iterations of the for loop and m is the number of iterations of the while loop.


Is it possible to use a for loop in place of a while loop?

Yes. while loop consist of only condition statement to make for loop look as while loop we can use syntax shown below: for(;condition;) eg: for(;i&lt;=n;)


Is possible to use a for loop in place of a while loop?

Yes, it's easy:Old: while (expression)statementNew: for (; expression;)statement


How do you write a program with do while loop so that the output is 123456 equals 720?

How do you write a program with do while loop so that the output is 123456 =720


When should use a while loop over a do loop?

Generally speaking a for loop looks like this:for(Initialization;condition;increment){Do Stuff}whereas a while loop looks like this:while(condition){Do Stuff}Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.


What is the syntax for writing a loop in pseudo code?

The syntax for writing a loop in pseudo code typically involves using keywords like &quot;for&quot;, &quot;while&quot;, or &quot;do-while&quot; to indicate the type of loop, followed by the loop condition and the code block to be executed within the loop.


What is main different between do while and while?

If you want to execute a statement which is in while loop at least one time you can use do- while loop. this is why because initially first statements will be executed then condition will be checked. but in case of while first condition will be check then statements will be executed


What is a nested loop in java?

A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for. For example, the inner loop can be a while loop while an outer loop can be a for loop.


How do you get the ouput as 11111 using while loop?

int i = 0; while( (i++) &lt; 5 ) { printf("1"); }


What are the similarities of while loop and a do while loop?

They both loop


What is a C programming to calculate the sum of 1-2-3-4-5 and so on using while loop a for loop and a do while loop?

#include using std::cout;using std::endl;int main(){int number(1);cout number;//using loop forint sum(0);for(int i(1); i


How can you define null statement in loop in C programming?

If you are using for loop for(;;); or you can also define condition and iterations but the loop has to close there itself without any statement inside it. In the similar way you can define while and do while loop without any statement.