Please register to participate in our discussions with 2 million other members - it's free and quick! Some forums can only be seen by registered members. After you create your account, you'll be able to customize options and access all our 15,000 new posts/day with fewer ads.
Can someone give a simple explanation for how a pointer works in a loop? For example, I don't understand what anything between "begin" and "end" means in this code:
@Pointer is a variable. Int tells you it is an integer (number). It could MyFavoriteAlien instead of @Pointer and you'd get the same result, which is that the loop (there is no loop in the example though) runs until the value of the variable is greater than 5 then the loop stops and the program goes to the next portion of code if there is any. @Pointer is set to the value of 1 to start the loop.
In this case break tells the program to stop running.
While @Pointer is < 10 is a bit superfluous since it never gets larger than 6 in the loop.
I'm a bit rusty, but normally there is a while at the top of the loop and an end while at the bottom.
begin
select Pointer = @Pointer
select @Pointer = @Pointer + 1
if @Pointer > 5
break
end
As far as I can tell all this code is going to do is increment Pointer to the value of 2, and stop. There is no code to tell it to go to the top of the loop and loop through it again.
Something like this:
While Pointer < 5
select Pointer = @Pointer: I don't understand the need for this at all.
select @Pointer = @Pointer + 1: I don't know enough about the language used to understand the need for select
if @Pointer > 5
break
end while
If I wrote it it would be:
While @Pointer < 7
@Pointer = @Pointer + 1
if @Pointer > 5
break
end while
It doesn't feel right, though. It's been too long since I wrote code... It's not right. Someone who still codes can do a better job, I'm sure.
Last edited by Tek_Freek; 06-04-2011 at 03:59 PM..
@Pointer is a variable. Int tells you it is an integer (number). It could MyFavoriteAlien instead of @Pointer and you'd get the same result, which is that the loop (there is no loop in the example though) runs until the value of the variable is greater than 5 then the loop stops and the program goes to the next portion of code if there is any. @Pointer is set to the value of 1 to start the loop.
In this case break tells the program to stop running.
While @Pointer is < 10 is a bit superfluous since it never gets larger than 6 in the loop.
I'm a bit rusty, but normally there is a while at the top of the loop and an end while at the bottom.
begin
select Pointer = @Pointer
select @Pointer = @Pointer + 1
if @Pointer > 5
break
end
As far as I can tell all this code is going to do is increment Pointer to the value of 2, and stop. There is no code to tell it to go to the top of the loop and loop through it again.
Something like this:
While Pointer < 5
select Pointer = @Pointer: I don't understand the need for this at all.
select @Pointer = @Pointer + 1: I don't know enough about the language used to understand the need for select
if @Pointer > 5
break
end while
If I wrote it it would be:
While @Pointer < 7
@Pointer = @Pointer + 1
if @Pointer > 5
break
end while
It doesn't feel right, though. It's been too long since I wrote code... It's not right. Someone who still codes can do a better job, I'm sure.
@Pointer is a variable. It could MyFavoriteAlien instead of @Pointer and you'd get the same result
I believe @Pointer is a pointer. It could very well be @MyFavoriteAlien and you would get the same result. It could not be MyFavoriteAlien, because MyFavoriteAlien would be a variable, and not a pointer.
OP, please clarify that you are talking about pointers here and not variables.
it is a data type, that points to another data type.
say you create an integer called "X", and set it equal to '5'
then you create a pointer called "Y", and set it equal to X.
if you were to change the value of integer X to '6', the value of pointer Y changes to '6' automatically.
Almost, but not quite accurate. You should clear it up so it's not confusing to the OP.
Please register to post and access all features of our very popular forum. It is free and quick. Over $68,000 in prizes has already been given out to active posters on our forum. Additional giveaways are planned.
Detailed information about all U.S. cities, counties, and zip codes on our site: City-data.com.