0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Solidity】(tips) for文の中のcontinue,breakについて

Posted at

今回はfor文の中のcontinue,breakについて下記します。
for文はループ処理として使用されます。
そのfor文の中で使用されるcontinueとbreakには下記の役割があります。
continue:ループ内の次の反復処理にスキップする
break:ループを抜ける

では、下記のsample関数を実行するとcheck1,check2,checkNumはそれぞれどのような値になるでしょうか。

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;

contract Sample {
    string public check1;
    string public check2;
    uint public checkNum;

    function sample()public {
        for(uint i; i<10 ;i++){
            if(i==3){
                continue;
            }
            check1 = "check1";
            
            if(i==5){
                break;
                check2 = "check2";
            }
            checkNum = i;
        }
    }
}

答えは下記となります。
check1:"check1"
check2:""
checkNum:4

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?