In VB we can use a step statement during a for next loop to step between the counter.My question is,is there any alternative to that in C++?
In VB we can use a step statement during a for next loop to step between the counter.My question is,is there any alternative to that in C++?
You could probably make one pretty easily. It's been a long time since I did VB, so if you could describe it's behavior in a little more detail I'd be happy to code something for you along that lines.
The 3rd part of the for loop is usally used to control the counter.
so given:
After every iteration of the loop it will add 1 to i.Code:for (int i=0; i < 10; i++)
aah... i got it.An alternative to:
would be:Code:for x=1 to 10 step 2
Is that right?Code:for (int x=0;x<=10;x+2);
Agh.... step... Now I know what you're talking about... must be like the loops in QBasic.
edit: yes, exactly
If the VB for syntax is anything like the Pascal for syntax then
would beCode:for x=1 to 10 step 2
Code:for (int x=1; x <= 10; x+=2)
um, you might like the dowhile statement if you came from VB (like me) because dowhile comes with VB too.
the syntax of dowhile is:
do{
'code'...
}
while(condition)
though this is different than for, the difference is that the for statement might not even be executed once if the conditions in the for declarations aren't met, but the dowhile statement is always executed at least once. This is because the conditions for the two functions are listed in 2 seperate places. The for statement's conditions are listed above the code, and therefore are checked before the code executes. The dowhile statement on the other hand has its conditions stated after the code. Therefore the code has to execute at least once before the conditions are checked for the loop. For more info just check back to the tutorials. Those are found at http://www.cprogramming.com.