-6

enter image description here

As seen above, the algorithm uses "do" after "For". I am aware this is only a pseudo-algorithm but is this theoretically okay?

I am not willing to share the entire algorithm as it is not my work.

Academic
  • 281
  • 3
  • 12
  • 1
    Firstly, a pseudo-algorithm should be language independent, follow whatever convention is followed by existing papers. Secondly, this question is more suited for http://academia.stackexchange.com/ . – Rahul Bharadwaj Feb 12 '21 at 06:09
  • Python and C++ have very little in common besides both of them being programming languages. Is **what** theoretically okay? In code like that "do" is just a word meaning "do the stuff listed right below here". Some programming languages have a `do` keyword, like Bash or Ruby, while many don't. – tadman Feb 12 '21 at 06:10
  • you need to share full picture, snippet of it won't provide you a good solution – sahasrara62 Feb 12 '21 at 06:14
  • Strange question, pseudo code doesn't have a *theory* that's what makes it pseudo code. – john Feb 12 '21 at 06:48

2 Answers2

3

In code like that "do" is just a word meaning "do the stuff listed right below here". Some programming languages have a do keyword, like Bash or Ruby, while many don't.

In Python:

for e in edges:
  # ...

In C++:

for (auto&& e : edges) {
  // ...
}

Neither of them uses do.

For contrast, Ruby uses do to define blocks, akin to function(e) { ... } in JavaScript:

edges.each do |e|
  # ...
end

And Bash where it's a necessary element of the loop:

for edge in $(edges); do
  # ...
done

The notation you're seeing there is just a convention used quite often in computer science, but it's basically just an English explanation.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Can you explain the use of `auto&&` in the iterative for loop in C++? I know that `&` is supposed to indicate a reference, but what does `&&` indicate? – Param Siddharth Feb 12 '21 at 07:17
  • 1
    It's a C++-ism meaning ["just give me a reference to the thing, whatever it is, preserving `const`-ness"](https://stackoverflow.com/questions/13230480/what-does-auto-tell-us) where `auto&` means "give me a mutable reference" normally, so you often need to specify `const auto&` which can be annoying. – tadman Feb 12 '21 at 08:16
0

I think that in this mathematical algorithm the "do" does not mean the same as in the syntax of a programming language. In C++ this "do" will be not the do { /* ... */ } while () construct, but simply the brackets after the for: for (/* edges e_wi */) { /* algorithm */ }.

That is, "do" in mathematics is just a syntactical construct that means "this is the body". So, you can't use "do" after a "for" loop.

roshi
  • 46
  • 4