No, this code will not run.

The main problem with the code is that you are missing some `end`
statements. You should close functions and control flow statements with
`end`. So your code would be.

    def exp(x,y)
      if y = 1
        return x
      end
      return x * exp(x, y-1)
    end

Another problem though is the misuse of `=` in place of `==`. While in
normal mathematics `=` does test for equality, this is not the case in
programming. Since `=` is reserved for variables, we use `==` to test
for equality.

    def exp(x,y)
      if y == 1
        return x
      end
      return x * exp(x, y-1)
    end

But a better way to write that code would be to use the shortcut-if
statement. You can put an if-statement following some code to only run
**that** line. So instead of writing this.

    if y == 1
      return x
    end

You could write this.

    return x if y == 1

This makes the code both easier to read and makes your intent clearer.
So in the end, we have revised your method to this.

    def exp(x,y)
      return x if y == 1
      return x * exp(x, y-1)
    end

Bryan Dunsmore

-- 
Posted via http://www.ruby-forum.com/.