# Why this cannot compiling

**URL:** <https://discourse.julialang.org/t/why-this-cannot-compiling/28242>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [August 31, 2019, 4:14pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242 "2019-08-31T16:14:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 4:14pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/1 "2019-08-31T16:14:41Z")

</div>

> **function** CountCell(commands::Vector{String}, n::Integer
> 
> cell = 0
> 
> **for** i in 1:n  
> **if** commands[i]==“up” && cell/n !=0  
> cell -=n
> 
> **end**
> 
> **if** commands[i]==“down” && cell/n !=n-1  
> cell +=n  
> **end**  
> **if** commands[i]==“right” && cell%n !=0  
> cell = cell-1  
> **end**
> 
> ```
> if commands[i]=="left" && cell%n !=n-1
> cell = cell+1
> end
> 
> ```

> ```
> end
> 
> ```

> ```
> return cell
> 
> ```
> 
> **end**
> 
> commands = [“right”,“right”,“right”,“right”,“right”,“down”]  
> println("Total " + CountCell(commands,4))

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 31, 2019, 4:45pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/2 "2019-08-31T16:45:20Z")

</div>

A couple of details to start with:

You need `commands :: Vector{String}` in the signature.

It would make sense to use `if ... elseif` in the loop.

Where you write `cell + 1` and `cell - 1` you probably want to modify `cell` instead of showing it. Typos?

---

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 4:49pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/3 "2019-08-31T16:49:12Z")

</div>

yes i mean for cell-1 ==\> cell = cell -1 and i fix it .

i also chanfe the func type from string to vector.

it still not compiling

---

<div class="post-metadata">

**Author:** ![feanor12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/feanor12/32/8212_2.png) [@feanor12](https://discourse.julialang.org/u/feanor12)\
**Post date:** [August 31, 2019, 4:53pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/4 "2019-08-31T16:53:17Z")

</div>

write :

```julia
for i in 1:n

```

This could also be used:

```julia
for cmd in commands

```

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [August 31, 2019, 4:55pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/5 "2019-08-31T16:55:23Z")

</div>

You have fancy quotes around `up`. Replace with straight quotes and it compiles.

---

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 4:55pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/6 "2019-08-31T16:55:48Z")

</div>

you are right. i fix it but it still not working.

the error is :

$julia main.jl  
ERROR: LoadError: MethodError: no method matching +(::String, ::Int64)  
Closest candidates are:  
+(::Any, ::Any, !Matched::Any, !Matched::Any…) at operators.jl:424  
+(!Matched::Complex{Bool}, ::Real) at complex.jl:247  
+(!Matched::Char, ::Integer) at char.jl:40  
…  
while loading /home/cg/root/9384358/main.jl, in expression starting on line 24

---

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 4:59pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/7 "2019-08-31T16:59:51Z")

</div>

no thier is no fancy quotes around up. this quotes is the same like around down/right/left.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 31, 2019, 5:00pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/8 "2019-08-31T17:00:09Z")

</div>

> [@PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530):
>
> This is a short post on how to use backticks (` and ```) to quote code, so it is easy to read. This post can be linked to new users who are confused by this feature. Why By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This makes it easier to read your code and help you. Displayed code looks like this: function displayed\_code(x::Int, y::Int) if x \< y println("x is smaller") else println("or not") end end Inline…

---

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 5:36pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/9 "2019-08-31T17:36:49Z")

</div>

any one can check it ?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 31, 2019, 5:53pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/10 "2019-08-31T17:53:16Z")

</div>

> [@Fuad\_Sami](#):
>
> `ERROR: LoadError: MethodError: no method matching +(::String, ::Int64)`

That’s because you are trying to add a string to an integer in the line `println("Total " + CountCell(commands,4))`. Just do

```julia
println("Total ", CountCell(commands,4))

```

instead and the code (with corrected quotes) runs.

By the way, I suspect from your other code that you intended the code `cell/n !=n-1` to do truncating integer division, like C or Python 2. In Julia (as in Python 3), using `/` with two integers gives you a floating-point result, e.g. `3/2 == 1.5`. If you want truncating division, use `div(cell, n)` or `cell÷n` instead.

---

<div class="post-metadata">

**Author:** ![Fuad\_Sami](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fuad_sami/32/16900_2.png) [@Fuad\_Sami](https://discourse.julialang.org/u/Fuad_Sami)\
**Post date:** [August 31, 2019, 6:05pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/11 "2019-08-31T18:05:56Z")

</div>

thanks a lot. now its work but the output its not what should to be.  
i think cuz the logic for julia.  
so the div(7,3) is 2 ?  
and 7%3 is 1 ?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 31, 2019, 6:15pm UTC](https://discourse.julialang.org/t/why-this-cannot-compiling/28242/12 "2019-08-31T18:15:53Z")

</div>

> [@Fuad\_Sami](#):
>
> so the div(7,3) is 2 ?  
> and 7%3 is 1 ?

Yes. (You could just try it and see. And/or get help by typing `?div` or `?%` at the Julia prompt.)
