首页 > 解决方案 > 一种返回芭蕾舞女演员中代码位置的方法

问题描述

条件检查后如何返回芭蕾舞演员中的代码位置

例如

**Start:**

int value = io:readln("Enter 10: ");
if (value != 10)
{
   **goto Start**
}

有没有办法在芭蕾舞演员中实现这一点,以便代码不断返回,直到输入正确的值。

标签: ballerina

解决方案


您可以尝试使用以下代码示例:

import ballerina/io;

function main(string... args) {
    while (true) {
        var value = <int>io:readln("Enter 10: ");
        match value {
            int i => {
                if (value != 10) {
                    continue;
                }
                break;
            }
            error e => io:println("Input is not a number.");
        }
    }

    // Following code will be executed if and only if the input is 10
    io:println("Success! Input is number 10.");
}

推荐阅读