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

Some more if/else weirdness #41

Closed
sts10 opened this issue Jan 31, 2023 · 1 comment
Closed

Some more if/else weirdness #41

sts10 opened this issue Jan 31, 2023 · 1 comment

Comments

@sts10
Copy link
Contributor

sts10 commented Jan 31, 2023

I was refactoring a function and found some weirdness with if/elsebranches in afor` loop.

In the playground, this outputs nothing.

my_arr = [4,5,6,7,8]
what_i_found = find_6_or_7(my_arr)
print 'Found: {what_i_found}' 

func find_6_or_7(an_arr):
    for an_arr each item:
        if item == 6:
            return 6
        else item == 7:
            return 7

But if I change the else to a second if, it runs as expected:

my_arr = [4,5,6,7,8]
what_i_found = find_6_or_7(my_arr)
print 'Found: {what_i_found}' 

func find_6_or_7(an_arr):
    for an_arr each item:
        if item == 6:
            return 6
        if item == 7:
            return 7

Using 2 ifs in this particular example isn't any less efficient than a if and else, but I think there are cases where it would be.

This time, I checked: I use all spaces for indents here.

@fubark
Copy link
Owner

fubark commented Jan 31, 2023

This should be fixed in 3343587.

@fubark fubark closed this as completed Jan 31, 2023
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