# Error with semi-colon, using a loop for writing to a file

**URL:** <https://discourse.julialang.org/t/error-with-semi-colon-using-a-loop-for-writing-to-a-file/24047>\
**Category:** New to Julia\
**Created:** [May 9, 2019, 7:52pm UTC](https://discourse.julialang.org/t/error-with-semi-colon-using-a-loop-for-writing-to-a-file/24047 "2019-05-09T19:52:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [May 9, 2019, 7:52pm UTC](https://discourse.julialang.org/t/error-with-semi-colon-using-a-loop-for-writing-to-a-file/24047/1 "2019-05-09T19:52:46Z")

</div>

Julia is reporting a strange syntax error with semi-colon, when I am trying to use a loop for writing to a file.

> function print\_selected\_entries(select::Array{Int64,1}, v::Array{Float64,1}, file::String)  
> N=size(select);  
> f = open(file, “w”);  
> for i=1:N  
> if select[i]==1  
> print(f,v[i],“\n”);  
> end  
> end  
> close(f);  
> end

This returns the strange output

> julia\> print\_selected\_entries(select,omegas,“t.txt”);  
> ERROR: MethodError: no method matching (::Colon)(::Int64, ::Tuple{Int64})  
> Closest candidates are: …  
> …  
> Stacktrace:  
> [1] print\_selected\_entries(::Array{Int64,1}, ::Array{Float64,1}, ::String) at /data/dass/Julia/t.jl:4  
> [2] top-level scope at none:0

---

<div class="post-metadata">

**Author:** ![jwd0023](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jwd0023/32/8416_2.png) [@jwd0023](https://discourse.julialang.org/u/jwd0023)\
**Post date:** [May 9, 2019, 8:41pm UTC](https://discourse.julialang.org/t/error-with-semi-colon-using-a-loop-for-writing-to-a-file/24047/2 "2019-05-09T20:41:57Z")

</div>

Change “N=size(select)” to “N=size(select,1)”.

The error is coming from the “for i=1:N” line. The way you have it now, N is a tuple that looks like (number\_rows, number\_columns). Instead, you want just the number of rows.

---

<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:** [May 9, 2019, 8:45pm UTC](https://discourse.julialang.org/t/error-with-semi-colon-using-a-loop-for-writing-to-a-file/24047/3 "2019-05-09T20:45:17Z")

</div>

Also, please use backticks to quote code:

> [@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…
