doz*_*zel 1 sql oracle plsql loops procedure
假设我有一个 for 循环
for i in array.first .. array.last loop
boolean := c(i) > d(i);
if boolean --is true then
exit the loop immediately and also exit the entire procedure
else if the boolean is never true til the end of the loop, exit the loop
and keep running other scripts in this procedure.
Run Code Online (Sandbox Code Playgroud)
我知道“EXIT”关键字需要位于循环内部,以便在满足条件时退出循环。并且“RETURN”需要位于循环之外,以退出程序。
但是如果我把'RETURN'放在循环之外,那么我想无论循环的结果是什么,当循环结束时它都会退出整个过程?
如果您想对此进行说教,则应该使用 EXIT 退出循环,然后使用 RETURN 退出过程(重复任何必要的测试),从而遵循结构化编程规则“过程应该只具有一个入口和一个出口”。实际上,99.999% 的程序员只会在循环体中编写 RETURN 代码,因为 A) 更清楚发生了什么(你不仅仅是跳出循环,而是从过程中返回),B )它更短。随你所愿吧。祝你好运。
| 归档时间: |
|
| 查看次数: |
32724 次 |
| 最近记录: |