Raised This Month: $32 Target: $400
 8% 

While Loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gior
Member
Join Date: Sep 2013
Location: Israel
Old 04-28-2015 , 15:09   While Loop
Reply With Quote #1

Hey,

I have a question about while loop.
Let's say I want to read from a file with a while loop:
PHP Code:
new Handle:File OpenFile("file.txt""r")
new 
String:buffer[128]
while(!
IsEndOfFile(File))
{
    
ReadFileLine(Filebuffersizeof(buffer))
    
PrintToServer("%s"buffer)

How the function "ReadFileLine" knows what line to read every time the loop start over?
I mean it starts from the top but how it knows how to read all the file?
I don't see here a option to set a line number or something like that, and yet, it is still reading the next line.

Any explanations?


Thanks in Advance

Last edited by Gior; 04-28-2015 at 15:10.
Gior is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-28-2015 , 15:22   Re: While Loop
Reply With Quote #2

The file pointer keeps track of the position inside the file that it is currently at.
So when it reads a line, it's current position is at the end of that line. When you read a line again, it remembers where it left off and gets the next line.
Then you just repeat that process for the whole file.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Gior
Member
Join Date: Sep 2013
Location: Israel
Old 04-29-2015 , 12:16   Re: While Loop
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
The file pointer keeps track of the position inside the file that it is currently at.
So when it reads a line, it's current position is at the end of that line. When you read a line again, it remembers where it left off and gets the next line.
Then you just repeat that process for the whole file.
Great explanation.
Thanks.
Gior is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode