Pfap
Member
Hi, when you use the continue key word doe it automatically add to the value of the iterator?
My issue is that I'm pulling instance id's from a grid and sometimes the value coming out is undefined.
The manual section for the keyword continue showed it being used with this style:
Which leads to the second part of my question. What is the difference between using the above versus the below:
Is it just style? I personally prefer the second usage, it seems easier for me to think about when j is changing even though I know it's at the end of the loop. Also, if using the second style do I need to add to j before calling continue?
Ok, sometimes just writing a forum posting can do wonders. I figured out the question about the operation of continue, still curious about the difference in for loops though.
I had to add to j before using continue
Code:
repeat(4){
show_debug_message(i);
if is_undefined(id_sprite[i]){ show_debug_message(i); show_debug_message("continuing"); continue; }
show_debug_message(i);
if id_sprite[i].sprite_index == sprite_index{
//run the code to add to score if the instance hasn't been tagged yet
event_user(4);
i += 1;
}
else{
i += 1;
}
}
The manual section for the keyword continue showed it being used with this style:
Code:
//my i's are auto capitalized so using j's
for(j = 0; j < 10; j++){
//your code here
}
Which leads to the second part of my question. What is the difference between using the above versus the below:
Code:
for(j = 0; j < 10;){
//your code here
j += 1;
}
Ok, sometimes just writing a forum posting can do wonders. I figured out the question about the operation of continue, still curious about the difference in for loops though.
I had to add to j before using continue
Code:
id_sprite[0] = undefined;
id_sprite[1] = undefined;
id_sprite[2] = undefined;
id_sprite[3] = undefined;
i = 0;
repeat(4){
show_debug_message("i at start of loop");
show_debug_message(i);
if is_undefined(id_sprite[i]){ show_debug_message(i); show_debug_message("i at continue of loop"); i += 1; show_debug_message("continuing"); continue; }
show_debug_message("i after continue");
show_debug_message(i);
if id_sprite[i].sprite_index == sprite_index{
//run the code to add to score if the instance hasn't been tagged yet
event_user(4);
i += 1;
}
else{
i += 1;
}
}