Fruitful Functions and Void Functions in Julia
Functions are one of the most useful tools when writing a program. Every programming language including Julia uses functions, it can be for keeping the code simple and readable or to keep the program secure from outside interference. In almost every programming language there are two types of functions:
- Fruitful Functions
- Void Functions
Fruitful Functions
These are the functions that return a value after their completion. A fruitful function must always return a value to where it is called from. A fruitful function can return any type of value may it be string, integer, boolean, etc. It is not necessary for a fruitful function to return the value of one variable, the value to be returned can be an array or a vector. A fruitful function can also return multiple values.
Example 1:
function add_f(a, b);
c = a + b;
return c;
end
d = add_f( 3 , 4 );
print (d)
|
Output:
Example 2:
function mul_f(a, b, c);
d = a * b * c;
return d;
end
x = mul_f( 2 , 4 , 6 );
print (x)
|
Output:
Void Functions
Void functions are those that do not return any value after their calculation is complete. These types of functions are used when the calculations of the functions are not needed in the actual program. These types of functions perform tasks that are crucial to successfully run the program but do not give a specific value to be used in the program.
Example 1:
function add_v(a, b);
c = a + b;
print (c);
end
add_v( 3 , 4 )
|
Output:
Example 2:
function mul_v(a, b, c)
print (a * b * c);
end
mul_v( 2 , 4 , 6 )
|
Output:
Last Updated :
25 Aug, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...