answersLogoWhite

0


Best Answer

example with two variables (j and d):

for (i=0; i<10; ++i)

{

int j=1;

double d=8.0;

... more statements ...

}

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you initialize more than one variable in a for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is do while loop in VB 6?

Structure: do (while(expression) or until(expression)) . . . loop (while(expression) or until(expression)) This is called a loop in VB and it is used to do something more than one times. It may be used without any of the parameters "while" or "until" but in such case you have to make your code exit of the loop or most likely your program is going to stop responding. The while parameter is used when we want the code in the loop to be executed WHILE the expression is True. Example: variable = variable + 1 The until parameter is used when we want the code in the loop to be executed until the expression gets True. Example: variable = variable + 1


What is looping?

prime a loop is that how mach time it executed either max time or minimum time


Why should you be careful not to place a statement in the body of a for loop that changes the value of the loop's counter variable?

By changing the loop counter variable within the loop can cause the loop to exit early or to loop more times than the limit. The is nothing that says that you can not change the loop counter variable within the loop, you may indeed want to do that. Just be careful and be sure of what will happen.


What is difference between for loop and while loop?

One first basic rule is that you should use the for loop when the number of iterations is known. For instance:The loop iterates over the elements of a collection.The loop iterates over a range of values which is known in advance at execution time.The object provides a way to iterate over its elements with a for statements (e.g files).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.The while loop can take every boolean expression as condition and permits therefore more complex end conditions. It is also the better choice if the iteration variable does not change evently by the same step or if there are more than one iteration variable. Even if you can handle more than one iteration variable in a for statement, the collections from which to choose the values must have the same number of elements.Note: In C 'for' and 'while' can be easily replaced by each other:while (exp) stmtfor (;exp;) stmtfor (exp1;exp2;exp3) stmt{ exp1; while (exp2) { stmt exp3}}


Which statements are nedded to control loop?

A For loop requires 3 parameters:for( int i = 0; i < 10; ++i ){}So, the first parameter - int i = 0 - shows the integer that you will be using to cycle with. This variable sometimes corresponds with what you're cycling through, so if you're using an array, array notation dictates that you can access the array with integers.The second parameter - i < 10 - says that if the i variable is less than 10, do the for loop.The third parameter - ++i - shows by how many you want to increment or decrement the variable by. This means that the for loop I have provided will run 10 times. (Remember: if you start at 0 - which all arrays and vectors e.t.c will do - you need to start your For loop at 0)

Related questions

How does a FOR loop work in GML?

FOR loops work as follows:{for( [initialize a variable]; [expression]; [increment the variable] ) {//Do this code}}Here as an example of a FOR loop:{for(i = 1; i < 10; i += 1) {show_message(string(i));}}What this will do is show a message 10 times displaying the value of "i" so you would get a message that says "1," another one after that saying "2," etc... The way this works is that you have the variable "i" initialized in the FOR loop. The FOR loop will keep looping until i >= 10, because the middle statement dictates that i must be smaller than 10 for the FOR loop activate. The third statement in the for loop is the statement that you increment the i variable with. If you change i += 1 to i -= 1 then the FOR loop would go on forever, freezing the game. This is a critical mistake to make when constructing a FOR loop (as is with any loop.)


Print 1-10 numbers using while loop?

public static void main(String args){ int counter = 0; //initialize the counter variable to 0 while (counter &lt; 10){ //while the counter variable is less than 10... counter ++; //increase the counter variable by 1 System.out.println(counter); //print the counter variable } }


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.


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);


Can you have more than one variable?

Yes, you can have more than one variable


What is do while loop in VB 6?

Structure: do (while(expression) or until(expression)) . . . loop (while(expression) or until(expression)) This is called a loop in VB and it is used to do something more than one times. It may be used without any of the parameters "while" or "until" but in such case you have to make your code exit of the loop or most likely your program is going to stop responding. The while parameter is used when we want the code in the loop to be executed WHILE the expression is True. Example: variable = variable + 1 The until parameter is used when we want the code in the loop to be executed until the expression gets True. Example: variable = variable + 1


Can an expression have more than one variable?

Yes, an expression can have more than one variable.


What is the variable of 5 more than s?

The variable of 5 more than s is s + 5.


What is the term for an equation with more than variable?

An equation with more than one variable is called a multivariate equation.


Can a experiment have more than one independent variable?

yes it can I've done a few experiments that have had more than one independant variable.


What is is an equation with more than one variable called?

Simultaneous equation* * * * *No, simultaneous equations are two or more equations that have all to be true at the same time (simultaneously) for the solution.An equation with more than one variable is a multivariate equaion.Area = 0.5*Length*Height or a = 0.5*l*h for the area of a triangle has more than one variables, but it is certainly not simultaneous.An equation with a variable is called a single variable equation. An equation that has more than one variable is called as a multi-variable equation. A polynomial equation has one variable in different powers: a common example is quadratic equations.


Is the DC inner loop longer than the outer loop?

No- the outer loop has to be longer than the inner loop.