TeX - LaTeX Asked on July 10, 2021
The title says it all.
What is the difference between a Function
and a Procedure
?
When should I use which?
According to algpseudocode
, these two are structurally the same, apart from their name:
algdef{SE}[PROCEDURE]{Procedure}{EndProcedure}%
[2]{algorithmicprocedure textproc{#1}ifthenelse{equal{#2}{}}{}{(#2)}}%
{algorithmicend algorithmicprocedure}%
algdef{SE}[FUNCTION]{Function}{EndFunction}%
[2]{algorithmicfunction textproc{#1}ifthenelse{equal{#2}{}}{}{(#2)}}%
{algorithmicend algorithmicfunction}%
From a programming perspective, the difference is embedded in the language and have the following commonly-used structure (in laymen's terms):
A minimal example indicating their typical usage:
documentclass{article}
usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
begin{document}
begin{algorithmic}
Procedure{name}{params}
State body
EndProcedure
Function{name}{params}
State body
State Return something
EndFunction
end{algorithmic}
end{document}
Correct answer by Werner on July 10, 2021
This is not at all a TeX-related question, but a function returns a value while a procedure does not (void
in C++). A procedure only performs some actions, it is invoked because of its side effects.
Answered by marczellm on July 10, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP