任何想法如何解释这些伪代码冒号?

问题描述 投票:3回答:1

这是我的第一篇文章。所以,请保持温柔。

我的教授给了我这个伪代码,但我不知道如何解释冒号和od;

我为他给我们的图像加了图像,但在下面键入了伪代码

Image of pseudocode

read12Bits() : 12Bit =
  declare Result : 12Bit = 0; 
  for i = 1 to 12
    do
      declare lBit : Bit = input() // get next bit 
      if ( lBit == 1 )
       then Result = (1 << (i-1)) + Result; //set bit at index i
    od;
  return Result;
pseudocode
1个回答
1
投票

如果我要解释的话:

  • read12Bits() : 12Bit:read12Bits是一个返回12Bit的方法
  • declare Result : 12Bit = 0:结果是12Bit类型的变量。结果设置为0
  • do od是一对。 do块以do开头并以od结束,类似于[shell脚本中的iffi

我想知道这是否是Algol 68语法:https://en.wikipedia.org/wiki/For_loop#1968:_Algol_68

© www.soinside.com 2019 - 2024. All rights reserved.