这是我的第一篇文章,请保持温柔。
我的教授给了我这个伪代码,但是我不知道如何解释冒号和“ od;”。
我为他给我们的图像加了图像,但在下面键入了伪代码
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;
如果我要解释的话:
read12Bits() : 12Bit
:read12Bits是一个返回12Bit的方法declare Result : 12Bit = 0
:结果是12Bit类型的变量。结果设置为0do
od
是一对。 do块以do
开头并以od
结束,类似于[shell脚本中的if
,fi
我想知道这是否是Algol 68语法:https://en.wikipedia.org/wiki/For_loop#1968:_Algol_68