Posted By:
Robert_Lybarger
Posted On:
Monday, April 10, 2006 07:57 AM
With your current approach, you'll probably need a boolean and some additional logic. You have four possible states to check for: (1) you haven't started a view/proc yet, (2) you found the start of a view/proc, (3) you're still in a view/proc but haven't found the end, (4) you found the end of the view/proc. Consider:
Consider:
boolean pending=false;
while (read line is not EOF) {
if (!pending) {
if (line contains view or proc.) {
//state #2
pending = true;
add the "--" or whatever
}
else {
//state #1
you're not in a[nother] view/proc yet
}
}
if (pending) { // don't use 'else'
if (line contains ';') {
//state #4
pending = false;
do whatever... you're finished
}
else {
state #3
you're in continuation of view/proc
but haven't found end yet
}
}
}
Note the 'if' I marked "don't use else" which allows the logic to fall through and catch both states #2 and #4 (start and end) on the same line.