Sign in to follow this  
BH2114

Nested If & while statements

Recommended Posts

I have a sequence as below which works:

	while(1)
private st = systime()
while(systime() - st < logInterval*60)
   delay(.2)
   if (logFlag==0)
      break
   endif
endwhile
 if (logFlag==0)
      break
      delay(.1)
   endif
FileHandle = File.Open(NewFileName,0,1,1,1)     
private string out= ChannelData 
File.Write(FileHandle,out)
File.Close(FileHandle)    
wait(.1)
endwhile
	

This sequence writes (channelData) to a file every (loggingInterval*60). When (logFlag =0), the while loop breaks and the sequence continues to other tasks.

I have one additional variable (step) that starts at 0 and increments by (1) to the value (8). when logFlag =0, step is reset to  =0

I would like to write (channelData) once each time (step) increments, in addition to the normal file writes that take place as a result of (logInterval*60).

Just cant figure out how to nest the if statement (if thats what should be used) and updating step in the same manner that (st) is being updated also does not seem to work.

Note: this appends to a file that was previously created.

Share this post


Link to post
Share on other sites

I would move the file writing part to a separate sequence function:

function writeLine()
   FileHandle = File.Open(NewFileName,0,1,1,1)     
   private string out= ChannelData 
   File.Write(FileHandle,out)
   File.Close(FileHandle) 

Then call it where you need it in your loops.  That way you can do your step check inside the inner loop and also log outside the loop.

BTW: watch your indentation.  3 spaces in for every block (while, if, etc), and 3 spaces out for end of block (endwhile, endif, etc.)

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this