answersLogoWhite

0


Best Answer

Typically, the variable is initialized in the first clause of the for statement, and incremented in the third clause. However, the language does not require any particular type of statement in these places.

The following is a typical example:

for (int i=0; i

In this example, the variable i is initialized in the first clause, and incremented in the third.

The same effect could be realized by putting the initialization and increment in other places:

int i=0; for (/* */; i++ /* */)

but this would be more difficult to read.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which part of the for loop is resposible for assigning a value to a variable?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

For loop in c language?

for(assigning initial value;condition;increment/decrement) { statement; }


How do you display 1 to 100 using loops in c?

To display 1 to 100 using loops in C, you must first declare a variable. This variable will be the one to be printed it's increasing values. The variable must increment by 1 every time the loop loops. While the loop counter does not exceed 100, the loop will continue. Example code: int counter = 0; int value = 0; for (counter = 0; counter <= 100; counter++) { value++; // (increment) increase value of variable "value" by 1 printf("%d\n", value); }


How do you end a while loop by accepting newline in integer variable?

A newline has ASCII character code 10, therefore you test for the integer value 10. That's not much use if the user needs to enter 10, therefore you should test the input before assigning the integer.


What are the index variable in the for loop?

The for loop uses a counter or an index variable to loop through the statements. This variable is used through the loop, changed and finally compared with the loop condition for consideration of the loop's next cycle. The variable(s) used inside the for loop for comparison (with the mentioned condition) and increment/decrement is know as the index variable. for example (Java) : for(int i=1; i<5; i++){ ... } in this example, integer 'i' is the index variable.


A variable used to store a value being computed in increments during a loop's execution is called?

an accunmulator


A variable declared inside the for loop control cannot be referenced outside the loop?

Yes. A variable declared inside the loop is a local variable for the code block enclosed by the {} statements of the for loop. The variable will not be available to be used by any code outside the code block.


A countdown loop operates by the loop control variable?

decremented


C plus plus what do you do if im stuck in an infinite loop?

There are three ways out of a loop.1. Satisfy the loop ending condition2. Execute a break statement3. Terminate the programPerhaps you are not changing the value of the variable that is used in the loop ending condition. Perhaps you are using a variable, such as an unsigned int, decrementing it, and expecting it to go negative. Suggest you run the program in a debuger and step through the loop.


A loop control variable that is incremented a specific number of times is known as?

A loop control variable is widly known as a "counter".


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


What is the last step in a loop usually?

increment the loop control variable


When a VBScript loop control variable is not altered during loop execution what kind of loop may result?

An infinite loop.