Modifying global variables in user defined function

Modifying global variables in user defined function - I am trying to modify a global variable inside a function passed as an argument. - Messages

#1 Posted: 6/30/2021 10:28:24 PM
stephen16

stephen16

0 likes in 2 posts.

Group: User

I am expecting the global variable value to change and maintain the change after exiting the function.

Example
#2 Posted: 6/30/2021 11:49:39 PM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Hi. The only way I know for a function to modify a variable is to pass it by reference to the function.

Clipboard01.jpg

Best regards.
Alvaro.
#3 Posted: 7/1/2021 12:03:51 AM
stephen16

stephen16

0 likes in 2 posts.

Group: User

Hi Alvaro,

Thank you for your reply. How do I do that? Could you share some sample.
#4 Posted: 7/1/2021 12:12:28 AM
Alvaro Diaz Falconi

Alvaro Diaz Falconi

992 likes in 1674 posts.

Group: User

Hi.

example_by_ref.sm (4 KiB) downloaded 33 time(s).

Clipboard01.jpg

Best regards.
Alvaro.
#5 Posted: 7/1/2021 8:35:00 AM
Jean Giraud

Jean Giraud

983 likes in 6866 posts.

Group: User

Native Smath has the exceptional feature of being algo style.
You can do what you want from in-situ command line.

AlgoCode.PNG
1 users liked this post
Oscar Campo 7/1/2021 10:50:00 AM
  • New Posts New Posts
  • No New Posts No New Posts