05-18-2024, 08:13 PM
(This post was last modified: 05-18-2024, 08:15 PM by Kernelpanic.)
I have a question regarding loop variables.
A loop variable should actually only be declared before or direct in use, something like in C (all loop variables are local, related to the loop):
In Basic, everything is usually declared at the beginning of the program, and there is rarely something like this:
As mentioned, is it possible to do it in Basic like in C, without much effort, or does it not fit into Basic's grammar at all?
A loop variable should actually only be declared before or direct in use, something like in C (all loop variables are local, related to the loop):
Code: (Select All)
#include
#include
int main(void)
{
int i;
for (int i = 0; i < 5; i++)
{
printf("\n%2d", i);
}
printf("\n\n");
for (int i = 0; i < 5; i++)
{
printf("\n%2d", i);
}
printf("\n\n%2d", i = 10);
return(0);
}
"i" is now really 10!In Basic, everything is usually declared at the beginning of the program, and there is rarely something like this:
Code: (Select All)
Option _Explicit
'. . .
Dim As Integer i
For i = 1 To 5
Print i
Next
Print
For i = 1 To 3
Print i
Next
Print
Print i + 2
And the last "i" will be taken. Of course, because it's not really local.As mentioned, is it possible to do it in Basic like in C, without much effort, or does it not fit into Basic's grammar at all?