We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
for loops (Read 757 times)
for loops
Apr 28th, 2010, 2:05pm
 
Is
Code:
for(int i = 0 ; i < 10 ; i++){ 


Bad syntax?
should int i; be called before the for loop?
Re: for loops
Reply #1 - Apr 28th, 2010, 2:25pm
 
this is a common shortcut. IMO it's ok and makes the code easier to read.
Re: for loops
Reply #2 - Apr 28th, 2010, 2:31pm
 
ok thank you, just wondering because my sketch will randomly crash and its filled with these for loops so just trying to narrow down the problem
Re: for loops
Reply #3 - Apr 29th, 2010, 2:09am
 
Not only that, but it limits the scope of the i variable to the for loop. Which is generally better (limit scope of your variables to the minimum needed to avoid possible side effects), but also allows you to have several for loops with the same variable in the same block.
Page Index Toggle Pages: 1