Unknown variables in VEX

   2938   2   1
User Avatar
Member
2 posts
Joined: July 2017
Offline
Hi! I am new in VEX and programming and my questons are noob, but I can't find answers on official site and forums. need help from community. I'd appreciate if you help me. The first answer is about variable nm in operator “for”. For example:

for (int nm=0; nm<max_nm; nm++)

“nm” was not defined by myself with other variables. Is it a number of iteration? The loop will broke when variable “nm” will reach the number which contains in variable max_nm, will not it? Please correct me.

Second answer concerns another variable “n” which was not defined too. For example:

foreach(int n; neighs_all)

“neighs_all” is an array, it contains integers. Is variable “n” a number of integer contained by this array?

I have read about functions “for” and “foreach” on sidefx.com, but I didn't find info about undefined variables which used with this functions. Please help with materials for learning.
User Avatar
Member
2036 posts
Joined: Sept. 2015
Offline
for (int nm=0; nm<max_nm; nm++)

Yes, ‘nm’ is being used to count through the iterations of the for loop.

And yes the loop will finish after it has completed the iteration defined by one integer less than the value of max_nm.

If you want to test and play to see the results of different inputs do something like this:

int max_nm = 5;

for (int nm=0; nm<max_nm; nm++)
{
printf("This is iteration %g\n", nm);
}

A console window will pop up and print out a line for each iteration.
Edited by BabaJ - Aug. 11, 2017 19:11:43
User Avatar
Member
2 posts
Joined: July 2017
Offline
Thank you for help! It's useful advice.
  • Quick Links