Text FormattingAlgorithm newbie question

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
aquafina
Posts: 8
Joined: Tue Apr 12, 2011 10:30 am

Algorithm newbie question

Post by aquafina »

Hello,

I am new to Latex and extremely new to the algorithm stuff in Latex.
Please look at this simple code I downloaded from the internet.

Code: Select all

Code, edit and compile here:
\usepackage{algorithm}
\usepackage{algorithmic}
\begin{document}
\begin{algorithm}
\begin{algorithmic}
\STATE{$S \leftarrow 0$}
\STATE{$i:=0$}
\FOR{$i=0$ to $10$} \STATE a[i]:=0
\ENDFOR
\IF{$x>y$} \RETURN{true}
\ELSE \RETURN{false}
\ENDIF
\end{algorithmic}
\end{algorithm}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
As far as I can interpret from this code, it should display:
S<-0
i:=0
for i=0 to 10
a:=0
if x>y
return true
else
return false


But the output is simply:
S<-0i:=0i=010x>y

Would really appreciate if someone could answer these questions:
a) Why is everything in the same line? And why no space?
b) Why is it not displaying the keywords like for, if?

Thank you

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

aquafina
Posts: 8
Joined: Tue Apr 12, 2011 10:30 am

Re: Algorithm newbie question

Post by aquafina »

I am sure the experts must be knowing the answer but just for the future reference for newbies, the .sty file such as algorithm.sty needs to be in the same folder as the latex file.
Post Reply