簡體   English   中英

如何在不兩次初始化布爾值的情況下使用while循環條件?

[英]How to use a while loop condition without initializing a boolean twice?

簡化此表達式的最佳方法是什么,這樣我就不必兩次設置colFinished了? (在外循環的每次運行中,colFinished必須重置為false)

boolean colFinished = false;
    for (int c = 0; c < SIZE; c += 1) {
        colFinished = false;
        while (!colFinished) {
            for (int r = 1; r < SIZE; r++) {
            ...

如果在for循環外沒有使用colFinished ,請嘗試:

for (int c = 0; c < SIZE; c += 1) {
    boolean colFinished = false;
    ...............

否則,我認為別無選擇。

您可以在第一個for循環中聲明變量:

for (int c = 0; c < SIZE; c += 1) {
    boolean colFinished = false;
    while (!colFinished) {
        for (int r = 1; r < SIZE; r++) {
        ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM