# What is the most used way to write for-loop as pseudocode?

• for $e\leftarrow1$ to 8 do
• for $e\in[1,8]$ do
• for $e\in\{x\in\mathbb{N}|1\le x\le8\}$ do

What is more preferred?

Just use whatever is clearest in your particular situation. Pseudocode is not a formal language with formal syntax.

Note that for $e\in [1,8]$ do doesn't necessarily imply that the values $1$, $2$, ..., $8$ are assigned in any particular order. Note that $\{x\in \mathbb{N}\mid 1\leq x\leq 8\}$ is somewhat redundant: an algorithm can't possibly loop over all the reals or rationals between $1$ and $8$, so the set can only really be a set of natural numbers. Finally, note that the association $\mathrm{e}=2.71828\ldots$ is very strong, so $e$ is often a poor choice of variable name.

• Thus, the most prefered way for looping from 1 to 8 is the first choice after replacing e with another variable. Right? – Abdulkader Jun 6 '18 at 14:07
• Of the three options you give, I think that's the one. But something like "for $i = 1$ to $8$ do" would also work: the most important thing is to be clear. – David Richerby Jun 6 '18 at 14:17

Pseudocode does not need to be so mathematical just for the case of being fancy. Making your algorithms understandable is always priority number one.

S = Dynamic array with integers
P = New empty AVL Tree

for every element x in S
P.insert(x)


Something like this is very easy to follow and does not include any form of formal descriptions. If the formal descriptions are important to understand, then we could of course show them just to clearify. The most preferable for the one receiving your pseudocode is that its simple and easy to follow.

The first one is much more compact and widely used specially in books like Introduction to Algorithms ,pseudocodes are meant to be simple and every reader with a little background of knowledge would be able to understand it