-1

Im working on programming solutions to mutexes and semaphores. Most loops I've dealt with here are:

while(true)
{
/* do nothing*/
}

I came across some pseudocode for an algorithm where they have

while choosing[i] do skip ;

(choosing is an array of booleans)

So is do skip the same as "dont do anything"?

I'm going to implement the psuedocode in java.

k29
  • 641
  • 6
  • 26

2 Answers2

1

use continue

while(true)
{

//condition
 continue;
}

See oracle docs on Branching Statements

The continue statement skips the current iteration of a for, while , or do-while loop.

See the example given by Oracle

 public static void main(String[] args) {

        String searchMe = "peter piper picked a " + "peck of pickled peppers";
        int max = searchMe.length();
        int numPs = 0;

        for (int i = 0; i < max; i++) {
            // interested only in p's
            if (searchMe.charAt(i) != 'p')
                continue;

            // process p's
            numPs++;
        }
        System.out.println("Found " + numPs + " p's in the string.");
    }

Here is the full demo code

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

I think it is more like:

if(! choosing[i]) {
      //Do some logic
}
Rami
  • 7,162
  • 1
  • 22
  • 19
  • Thanks that makes sense. This is essentially `continue`. I just dont see why they would have `do skip` because in the psuedocode there is no other logic that comes afterwards within the `while` loop. – k29 Sep 21 '13 at 10:52