开发者

How would this code segment look as pseudo-code?

I have this code:

for(iteration<string> it=name_list.iterator();it.hasNext();)

What would be a开发者_StackOverflow中文版 suitable pseudo-code representation for the above code?


Since pseudo-code is meant to be more human-readable, I'd simply opt for something like:

for each name in name_list:
    do something with name

You shouldn't have any need to put implementation details like iterators in your pseudo-code, rather you should simply specify intent. And I find the Python style of coding suits this sort of thing perfectly.

You should also use more descriptive names than it. I'm assuming that's for iterator but it gives absolutely no indication as to what the variable is. This is something you should aim for not just in pseudo-code but in real code as well.


The easiest way to make real code into pseudocode is to screw it up. :-) mwahahaha!

That could turn into

for each iteration of name_list.iterator as it

It could turn into hundreds of others too!


"For each item in name_list" at least that's probably the intention. This code on its own is just an infinite loop though because it never moves the iterator

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜