Can anyone translate this algorithm?

Let x[n] = x[0],…,x[n-1] be an array of given integers to search.
Let Position be an integer to store the array index of the item we are searching for.
Let Value be the value we are searching for.
For 0 i = to 1 n − , do the following:
If( x[i] = Value )
Position = i;
Break;
Else
Continue;

Translate to what?

You apparently continue on the same program that you mention here: http://www.cplusplus.com/forum/beginner/154915/


Conditions and loops: http://www.cplusplus.com/doc/tutorial/control/

Your algorithm is ok, save one little question: What if the array does not contain the Value? What should the Position be in that situation?

To C++ I didn't know if I should put that or if it would be redundant putting that. And yes, same program, asked my teacher about the loops and he said that would be fine to use even though that is in the next lesson haha! Thanks for the link!
Topic archived. No new replies allowed.