answersLogoWhite

0

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

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Basic Math

How does a WHILE loop work in GML?

The while loop works as follows:{while( [expression is true] ) {//Do this code}}The while loop re-runs until the expression contained within the parentheses is false. Take a look at this example:{while(!place_meeting(x,y,obj_ground)) {y += 1;}}This while loop tells the object to move down one pixel until it collides with obj_ground. Unfortunately, nothing guarantees that this loop will not run forever. Always make sure that when you construct a while loop that you make sure that it does not run forever. Take a look at this whileloop:{while(obj_ball.y < y) {draw_sprite(sprite_index,0,x,y);}} This while loop will run for ever. Why? It does not have any statements that insure that the while loop aborts. Again, Always make sure that when you construct a loop that you put statements in the loop that will eventually abort the loop. y -= 1; is the statement in this new while loop that eventually aborts the loop:{while(obj_ball.y < y) {draw_sprite(sprite_index,0,x,y); y -= 1;}}


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

An infinite loop.


What value of flag will cause this loop to terminate?

To determine the value of the flag that will cause the loop to terminate, you need to examine the loop's condition. Typically, a loop continues to execute as long as the flag is set to a specific value (like true or 1). Therefore, changing the flag to its opposite value (like false or 0) will usually lead to the loop's termination. For a precise answer, the specific condition used in the loop is needed.


What are the differences between a condition-controlled loop and a count-controlled loop?

A Condition-Controlled loop keeps going until a certain condition is met, like say the user clicks a button, or the world ends or something. A Counter controlled loop keeps going until it has run a certain number of times. For example if you create a variable x=0. And then every time your look runs you increase x by 1 (x=x+1), you can tell your loop to keep running until x=5. That way the loop would run 5 times until the *COUNTER* reaches 5. This would be a counter controlled loop


What is the purpose of wend statement in while loop in gw-basic?

While--wend statement is used to execute a loop until a given condition is true.if the condition is false the loop ends and the program continous to the line following eend.

Related Questions

How is a while loop different from a do until loop in gml?

In any programming language, a "while" loop and a "do until" loop are the same except for 1 difference. In order to enter a while loop, the condition must always be true. But in a do until loop, if the condition was false, the block of code inside the loop will always be ran at least once. Example: while (false) { // code here } in this example, the code inside the while loop will never run, but in the following example: do { //code here } until(false) although the condition is false, the code will be run 1 single time and the exists the loop.


How does a WHILE loop work in GML?

The while loop works as follows:{while( [expression is true] ) {//Do this code}}The while loop re-runs until the expression contained within the parentheses is false. Take a look at this example:{while(!place_meeting(x,y,obj_ground)) {y += 1;}}This while loop tells the object to move down one pixel until it collides with obj_ground. Unfortunately, nothing guarantees that this loop will not run forever. Always make sure that when you construct a while loop that you make sure that it does not run forever. Take a look at this whileloop:{while(obj_ball.y < y) {draw_sprite(sprite_index,0,x,y);}} This while loop will run for ever. Why? It does not have any statements that insure that the while loop aborts. Again, Always make sure that when you construct a loop that you put statements in the loop that will eventually abort the loop. y -= 1; is the statement in this new while loop that eventually aborts the loop:{while(obj_ball.y < y) {draw_sprite(sprite_index,0,x,y); y -= 1;}}


How do you use gml?

Go to yoyogames.com, they have a bunch of tutorials. You could also go to, gmc.yoyogames.com. It's the forum of gml game makers.


How is the density of an object in kgl related to its density in gml?

If kgl is kg/L and gml is g/mL these densities are equal.


What is the difference between GML Geography mark-Up Language and G-XML?

GML is a standard of the OGC and ISO (ISO 19136). G-XML is a standard of the Japanese Standards Association (JSA). Both standards are based on XML for the encoding of geographic information, however, G-XML is focused on location based services. G-XML is written in GML as a GML application schema.


What is the density of copper gml?

8.92 g/mL


Is there a real programming language that resembles GML - the language in Game Maker?

GML IS a real programming language. But anyway, all programming languages are about the same, with different syntax.


What expression can be found to represent the total work done by the agent pulling the loop?

The total work done by the agent pulling the loop can be represented by the expression &quot;work equals force times distance.&quot;


What liquids will be the unkown water 9982gmL toluene 8669 gmL clorofomo 14832 gmL ethanol 0789 gmL?

the correct density numbers are the following water= 0.9982 g/mL Toluene= .8669 g/mL Clorofomo 1.4832 g/mL Ethanol= .789 g/mL


Why does a generator work?

When a conductive loop is moved through a magnetic field, an electric current is produced in the wire loop. This is the basis of electrical generators.


What programming language is used for GameMaker?

GameMaker uses its own prgramming language, the Game Maker Language (GML) which was developed by Mark Overmars. GML supplements the drag &amp; drop system within Game Maker.


If water has a density of 1.0gmL and a test liquid has a density of 1.1 gmL pouring equal portions into a cup will cause what reaction?

The denser liquid (1.1 gmL) will sink below the less dense liquid (1.0 gmL). The liquids will form two distinct layers in the cup based on their densities, with the denser liquid at the bottom and the less dense liquid on top.