Checking variable value in run time

Hello:

I just wanted to know how could I check the value of a variable in the run time?

Is there any way to do that without interrupting the run?

Thanks

Annesha

 

 

3 Answers



0



You have a few options depending upon what you are trying to do.

I think the best option is probably to run your program under the debugger. When your code is running under the debugger, you can add breakpoints during the run so that you can pause the program and check the values of any variables at that point. When you are done looking at the variables, you can continue running the program from that point.

You can also add a print statement to your program to periodically print out the value of a variable if you just want to see it changing over the course of your program.

You could also use the key function to have GAUSS print the value of a variable when you hit a specified keystroke, but in most cases one of the first two options is best.

aptech

1,773


0



Hello,

Thanks much for your response. I actually did not want to check it for debugging purpose.

I am actually running a code where a function is being called multiple times from a loop. So I just wanted to check whether there is any way to check the value of the loop control variable, so that I know how many times the execution of the function is completed without interrupting the program.

Thanks.

Annesha

 

 



0



For this purpose, you can either add print statements at regular intervals so you can always see where the program is at. For example, to print out the counter at every 100 iterations, you could do this:

for i(1, 1e3, 1);
   if (i % 100) == 0;
      print i;
   endif;
endfor;

Alternatively, you can use the key function to tell your GAUSS program to print out the current iteration whenever you enter a particular key into the GAUSS program input/output window. For example, the code below will print out the value of the GAUSS variable ctr every time that the key p is entered.

ctr = 1;
for i(1, 1e6, 1);
   if key() == vals("p");
      print ctr;
   endif;
   ctr = ctr + 1;
endfor;

The key function returns the numerical ASCII value of the last key that was input to GAUSS. For example, the ASCII value of lower case 'p' is 112. If you enter a 'p' into the GAUSS program input/output window while the above code snippet is running, the key function will return 112.

The vals function returns the ASCII value of each character that is passed to it in a string. The return of vals("p") will be 112.

aptech

1,773

Your Answer

3 Answers

0

You have a few options depending upon what you are trying to do.

I think the best option is probably to run your program under the debugger. When your code is running under the debugger, you can add breakpoints during the run so that you can pause the program and check the values of any variables at that point. When you are done looking at the variables, you can continue running the program from that point.

You can also add a print statement to your program to periodically print out the value of a variable if you just want to see it changing over the course of your program.

You could also use the key function to have GAUSS print the value of a variable when you hit a specified keystroke, but in most cases one of the first two options is best.

0

Hello,

Thanks much for your response. I actually did not want to check it for debugging purpose.

I am actually running a code where a function is being called multiple times from a loop. So I just wanted to check whether there is any way to check the value of the loop control variable, so that I know how many times the execution of the function is completed without interrupting the program.

Thanks.

Annesha

 

 

0

For this purpose, you can either add print statements at regular intervals so you can always see where the program is at. For example, to print out the counter at every 100 iterations, you could do this:

for i(1, 1e3, 1);
   if (i % 100) == 0;
      print i;
   endif;
endfor;

Alternatively, you can use the key function to tell your GAUSS program to print out the current iteration whenever you enter a particular key into the GAUSS program input/output window. For example, the code below will print out the value of the GAUSS variable ctr every time that the key p is entered.

ctr = 1;
for i(1, 1e6, 1);
   if key() == vals("p");
      print ctr;
   endif;
   ctr = ctr + 1;
endfor;

The key function returns the numerical ASCII value of the last key that was input to GAUSS. For example, the ASCII value of lower case 'p' is 112. If you enter a 'p' into the GAUSS program input/output window while the above code snippet is running, the key function will return 112.

The vals function returns the ASCII value of each character that is passed to it in a string. The return of vals("p") will be 112.


You must login to post answers.

Have a Specific Question?

Get a real answer from a real person

Need Support?

Get help from our friendly experts.

Try GAUSS for 14 days for FREE

See what GAUSS can do for your data

© Aptech Systems, Inc. All rights reserved.

Privacy Policy