Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A difference between while and for #464

Open
s5unty opened this issue Dec 18, 2021 · 1 comment
Open

A difference between while and for #464

s5unty opened this issue Dec 18, 2021 · 1 comment

Comments

@s5unty
Copy link
Contributor

s5unty commented Dec 18, 2021

#!/usr/bin/env abs

f foo() {
    for t=2; t>0; t=t-1 {
        if arg(2) != "ok" {
            sleep(100)
            continue
        }
        return [0, "ok"]
    }
    return [1, "ng"]
}

f bar() {
    t = 2
    while t > 0 {
        t = t - 1
        if arg(2) != "ok" {
            sleep(100)
            continue
        }
        return [0, "ok"]
    }
    return [1, "ng"]
}

a, b = foo()
echo("foo(%s): %s", a, b)

x, y = bar()
echo("bar(%s): %s", x, y)
% ./bug.abs ok
foo(0): ok
bar(1): ng

% ./bug.abs ng
foo(1): ng
ERROR: identifier not found: x
	[33:21]	echo("bar(%s): %s", x, y)
@AndrewSav
Copy link

continue does not have a special meaning for while loops that it has for for loops, therefore, in bar continue simply terminates the function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants