對於此代碼:布爾不停止的情況,即使設定爲假
for crop in database:
print("The current crop is :", crop)
x.all_crop_parameters_match_the_PRA_ones = True
while x.all_crop_parameters_match_the_PRA_ones :
ASSESS_Tmin(crop, x, PRA)
print("x.all_crop_parameters_match_the_PRA_ones = ", x.all_crop_parameters_match_the_PRA_ones)
ASSESS_Water(crop, PRA, x)
print("x.all_crop_parameters_match_the_PRA_ones = ", x.all_crop_parameters_match_the_PRA_ones)
ASSESS_pH(crop, PRA, x)
我得到如下結果:
The current crop is : FBRflx
Checking minimum Temperatures...
x.all_crop_parameters_match_the_PRA_ones = False
Checking the Water Resources...
Verifying if the Water Resources match with the Tmin supported by the crop...
x.all_crop_parameters_match_the_PRA_ones = False
The soil pH of this PRA matches to the crop requirements.
This crop is edible for the current PRA !
我不明白爲什麼PROGRAMM看到X。 all_crop_parameters_match_the_PRA_ones爲False,仍然運行下一個功能,而不是斷開循環並切換到下一個裁剪。
x是一個包含我使用和修改的所有變量的類,它是我的代碼的幾個函數。它可能是一個錯誤,因爲布爾來自一個類?
它只停止的下一個循環...你想讓它在的中途停止執行代碼裏面呢?你必須明確的「break」來打破它......你發佈的內容看起來像預期的行爲。 – DSLima90