将 ada 代码转换为其 C
我有一段如下所示的 ada 代码,它是一个简单的 switch case 语句。有没有更好的方法可以将其转换为 C。
for I in 1..100 loop
case I is
when 100 =>
Dollars := Dollars + 1;
when 25|50|75 =>
Quarters := Quarters + 1;
when 10|20|30|40|60|70|80|90 =>
Dimes := Dimes + 1;
when 5|15|35|45|55|65|85|95 =>
Nickles := Nickles + 1;
when others =>
Pennies := Pennies + 1;
end case;
end loop;
现在通过为 case 中的每个值添加 switch 和 case,我可以进行该转换,但是看来你的代码太大了。是否有其他简单而紧凑的方法。如果问题不清楚,请回复我?
I have a piece of ada code shown below which is a simple switch case statements.Is there any better way to convert this into C.
for I in 1..100 loop
case I is
when 100 =>
Dollars := Dollars + 1;
when 25|50|75 =>
Quarters := Quarters + 1;
when 10|20|30|40|60|70|80|90 =>
Dimes := Dimes + 1;
when 5|15|35|45|55|65|85|95 =>
Nickles := Nickles + 1;
when others =>
Pennies := Pennies + 1;
end case;
end loop;
Now by adding the switch and the case for each values in the case,i can do that conversion,But it seems tyo make the code too big.Is there anywa other simple and compact way.Please get back to me if the question is not clear?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试:
Try:
不太漂亮,但仍然有效。如果性能很重要,您需要将其效率与@unicornaddict的答案进行比较,该答案比我的更干净。
Not quite as pretty, but still efficient. If performance is at a premium, you'll want to compare the efficiency of this with @unicornaddict's answer, which is cleaner than mine.