PDA

View Full Version : while loops


fred22
10-13-2005, 11:48 PM
I have a bit of a problem with while loops.
I understand the problems associated with while loop execution and overflow when the conditions are not meet. So its possible my problem is something else......example

$readLine = `fgetline $fileId`;
while ( size($readLine) > 0 )
{
tokenize $readLine $buffer;
// I'm looking for specific lines.
$match = ! `strcmp $compar $buffer[0]`;
if ($match)
{
// check for sub lines and exit loop apon specific text condition meet
// so tun another while loop
$readLine = `fgetline $fileId`;
tokenize $readLine $buffer;
// I'm looking for specific lines.
$match = ! `strcmp $compar2 $buffer[0]`;
while ( ! $match )
{
$readLine = `fgetline $fileId`;
tokenize $readLine $buffer;
// the reason for this is the lines have different data
// and need to be broken up into different sets of data
}
// continue when condition is meet.


So here is my delema...The reason for the nested while loop is to continue reading data until a condition is meet. But what you see there will not work even though the $match condition is met, an if staement won't work because it will obviously not continue looping.

I hope this makes sense, thanks heaps.

fred22
10-14-2005, 01:28 AM
Ok so I seem to have solved the problem....
It was that I was tokenizing the line with a character as the splitter, this was causing my string comparsion condition to never be met. I also ended up inserting a few if statements to test for the match before the while loop could so certain parts of the statement would not execute, maybe this is bad coding but I could not think of another way around it.

I would appreciate any input or suggestions on achieving this same thing.

CGTalk Moderation
10-14-2005, 01:28 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.