0

having a little trouble trying to convert this pseudo code into python, could any help

receiveFile () {
   lastblock := 0
   newblock  := 0 ;
   repeat
      repeat
         event := getFrameFromUDP(m) ;
         case event of


         data   :  newblock := getBlockNoFromFrame(m) ;
                   transmitAckOverUDP(newblock) |
         timeout:  transmitAckOverUDP(lastblock)

         esac
      until newblock==lastblock+1 ;
      lastblock = newblock ;
      storeFrameInMemory(m)
   until frame size < 512 bytes
}
4
Contributors
4
Replies
25
Views
4 Years
Discussion Span
Last Post by vegaseat
0

this is my attempt but need help finishing it

recieveFile ()
    {
        lastblock = 0 
        newblock = 0 
        do {
            do {
                (packet, (address,port)) = sock.recvfrom(512+4)
                event = getFrameFromUDP(m) ;
                switch(of) {
                    case data:
                        newblock = getBlockNoFromFrame(m)
                        break;
                    case timeout:
                        transmitAckOverUDP(lastblock)
                        break;
                    }
                while newblock == lastblock+1
                {
                    lastblock = newblock;
                    storeFrameInMemory(m)
                }
            while size < 512;
}
1

you said python right?

while (something < otherthing):
    [do this stuff]
    [down here]

and case switches become if, elif, & else.

if (data):
    [do something with data]
elif (timeout):
    [do something if timed out]
else:
    # no data, no timeout, what do we do?
    [do something else]

...no offense, i know not everyone is a python programmer, but this reminds me of that joke about how to get curly braces in python..

if (x): #{
    [do something]
#}
else: #{
    [nevermind]
#}

(they're comments)

3

Interestingly, Python syntax is closer to normal pseudocode than any other computer language.

Votes + Comments
very true, the syntax is so obvious it almost feels 'wrong' coming from another language.
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.