【发布时间】:2020-06-22 11:46:26
【问题描述】:
我有以下代码:
let str = "AA";;
let i =ref 0;;
let tam_str = String.length str -1;;
let aux_char = 'A';;
let b_aux1 = ref false;;
exception Out_of_loop;;
try
while !i <= tam_str do
let c_r = str.[!i] in
if c_r = aux_char then(
b_aux1 := true;
i := !i +1;
)
else(
b_aux1 := false;
raise Out_of_loop
)
done;
with Out_of_loop ->();
if !b_aux1 then
print_endline "1"
else
print_endline "0";
;;
我希望程序写入字符串“1”,但它返回的是“单位”。但我不明白为什么......有人可以解释为什么吗?
【问题讨论】: