Oscar Courchaine
Oscar Courchaine

Reputation: 346

Getting an "unexpected keyword_end" for if/else statements

def load x
    @maze_string = x
    @maze_string_split = x.chars.to_a
    string_counter = 0
    y=@height
    x=@width

    (0..(y*2+1)).each do |n|
        if @maze_string_split[counter] !=1
            puts "Error in given string, wall expected"
        else
            @maze_array[n] = @maze_string_split[counter]
            counter++
        end

        (0..(x*2)).each do |m|
            if n==0 || n==(y*2+1) || m==(x*2)
                if @maze_string_split[counter] != 1
                    puts "Error in given string"
                else
                    @maze_array[n][m] = @maze_string_split[counter]
                    counter++
                end
            else
                @maze_array[n][m] = @maze_string_split[counter]
                counter++
            end
        end
    end
end

I am getting the error in the title on the "end" statements at the conclusion of each if/else block. All seems well, but the errors remain. I tried looking to see if anyone else had this problem, but I can't find anything specific to my problem

Upvotes: 0

Views: 218

Answers (1)

Leo Correa
Leo Correa

Reputation: 19829

Ruby does not have a ++ or -- operator.

Ruby will not parse these out correctly in that is the reason you're getting an unexpected keyword_end, it is expecting another operand.

Replace the

counter++ with counter += 1

Also, note that your variable is not called counter but string_counter

Upvotes: 2

Related Questions