[Tex/LaTex] Beginner: problems with algorithmic, some commands not available

pseudocode

I am a real beginner in latex, and now I am struggling with using the algorithm package and algpseudocode to write some code.
What I did until now is:

\usepackage{algorithm}
\usepackage{algpseudocode}

\begin{algorithm}
\caption{My algorithm doing something....}
\begin{algorithmic}
\Function{findSomething}{$x, y$} \\
\(current\_value \gets 0\) \\
\(value\_found \gets false\) 
\While{\(value\_found \neq true\)}
\If{......}
% DO something, doesn't matter  \And    % WHERE I TRIED THE And command
 .......
\EndIf
\EndWhile \\
\Return \(x\) 
\EndFunction
\end{algorithmic}
 \end{algorithm}

Now I wanted to use commands like "and, or, to" but here they are not working, is this maybe another package than the once I loaded?
But still my second problem is, I found that i can define a command like:

 \algnewcommand{\Or}{\textbf{or}}

But when I then use the \Or, nothing appears on the final pdf :S. Or when I try to define:

 \algnewcommand{\And}{\textbf{and}}

Latex is telling me that the command already exists, but when I try to use it in my code (marked in the example) I get an error that the command is not available, :S

Best Answer

Defining \And and \Or works as you proposed and as you can see in the following example. However, you should make use of \State:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}

\algnewcommand{\Or}{\textbf{or}}
\algnewcommand{\And}{\textbf{and}}

\begin{document}
\begin{algorithm}
\begin{algorithmic}
\Function{findSomething}{$x, y$}
\State \(current\_value \gets 0\)
\State \(value\_found \gets false\)
\While{\(value\_found \neq true\)}
\If{......}
% DO something, doesn't matter  \And    % WHERE I TRIED THE And command
\State A \And{} B
\EndIf
\EndWhile
\State \Return \(x\)
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

A quote from the package documentation of algorithmicx (http://mirrors.ctan.org/macros/latex/contrib/algorithmicx/algorithmicx.pdf):

A simple line of text is beginned with \State. This macro marks the begin of every line. You don’t need to use \State before a command defined in the package, since these commands use automatically a new line.

For logical and/or operators in pseudo-code I personally use \land or \lor. Usually you should get around with the commands defined in algpseudocode. to is usually not a command in pseudo-code imho but maybe used in the first line of a for loop. Again you can use algnewcommand to define a to command. If you would like to typeset comments you might want to use \State \Comment And or to....