Calling a variable in println

Hello,
I want to multiply the numbers 1 to 12 by 2. How can I change the following code so that this operation happens in println?

for a=1 : 12
    println("$a * 2")
end

Thank you.

You can execute stuff by using $(...) before interpolation like

for a=1 : 12
    println("$(2*a)")
end

or to just complete your example this would print actually both

for a=1 : 12
     println("2 * $(a) = $(2*a)")
end
1 Like

Or just println(a * 2). The argument to println doesn’t need to be a string.

3 Likes

Hello,
Thank you so much.