How to compare a var to 0 ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to compare a var to 0 ?

Zipette
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Jeremy Tregunna
Problem seems to be that you’ve spelled Int as INt. Fixing that, and fixing Println to println resolves any issues when I punch this into the REPL.

If you’re still having issues, perhaps you can tell us what the exact error message says, and provide us with the actual subset of code that’s erroring. We might be able to help a bit better.

-Jeremy
On Jan 23, 2015, at 4:42 PM, Zipette <[hidden email]> wrote:

Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F5B689A7-5D24-4CA0-95A1-F501C6E95382%40tregunna.ca.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Kevin Greene
In reply to this post by Zipette
// Try this instead.
let a = 5
if a != 0 {
  println("hello world")
}

On Fri, Jan 23, 2015 at 2:42 PM, Zipette <[hidden email]> wrote:
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/CAEY8wq4GYXqmr%2B4w%2Bc2D_7NzEacO%2BF68360qRpcRrb3W9O%2Bgkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Zipette
I have try 
let a = 5
if a != 0 {
  println("hello world")
}

but the compiler says : "Expeted '{' after 'if' condition" . I do not realy undesrtand where is my error... Any other advizes ?

Thks

Le vendredi 23 janvier 2015 23:49:31 UTC+1, Kevin Greene a écrit :
// Try this instead.
let a = 5
if a != 0 {
  println("hello world")
}

On Fri, Jan 23, 2015 at 2:42 PM, Zipette <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="Cj8Hutt4Jm4J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">conta...@votrecalendrier.com> wrote:
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Cj8Hutt4Jm4J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-languag...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="Cj8Hutt4Jm4J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">swift-l...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;" onclick="this.href='https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com?utm_medium\75email\46utm_source\75footer';return true;">https://groups.google.com/d/msgid/swift-language/cf8a056c-ee34-4eb3-8c78-77cd9d6c31d3%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/25da4f69-471d-4a76-8f41-e6613738ebbf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Darrell Nicholas
In reply to this post by Zipette
Another thing, other than Int being spelled as INt and println having a capital P, you also have to have equal spaces on either side of your operator "!=". Either (a != 0) but you don't even need the parenthesis in this instance. 

var a:Int = 5
if a != 0 {
println("Hello world")
}

Hope that helps you. In a lot of cases you can have equal spaces or equal no spaces on either side of your operand, I think maybe on in assignments. a=5 or a = 5, but I
a= 5 or a =5 is wrong and will give an error. This is due to Swift's ability to do operator overloading. You could create an operator called a= that does something you define. The compiler looks at those spaces or lack or spaces due to this reason.

I am by no means a Swift expert, I've only been using it since June of last year ;-)

No really I just do this stuff as a hobby and this answer may already be answered by someone else, but I knew the answer to this one so I wanted to jump in and contribute where I could.

On Friday, January 23, 2015 at 4:42:31 PM UTC-6, Zipette wrote:
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/c9e773a3-ed07-471d-8b51-709cfe5656d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Zipette
Thanks a lot Darrell ! It was the problem ! I didn't let a the right spaces between terms, so you are completly true, the right formule is :

var a:Int = 5
if a != 0 {
println("Hello world")
}

As you notice, a space between "a" and "!=" and also a space between "=" and "0"

Thanks again for the time you spent on my question and also thanks to other one for their answers !
By



Le dimanche 25 janvier 2015 00:19:26 UTC+1, Darrell Nicholas a écrit :
Another thing, other than Int being spelled as INt and println having a capital P, you also have to have equal spaces on either side of your operator "!=". Either (a != 0) but you don't even need the parenthesis in this instance. 

var a:Int = 5
if a != 0 {
println("Hello world")
}

Hope that helps you. In a lot of cases you can have equal spaces or equal no spaces on either side of your operand, I think maybe on in assignments. a=5 or a = 5, but I
a= 5 or a =5 is wrong and will give an error. This is due to Swift's ability to do operator overloading. You could create an operator called a= that does something you define. The compiler looks at those spaces or lack or spaces due to this reason.

I am by no means a Swift expert, I've only been using it since June of last year ;-)

No really I just do this stuff as a hobby and this answer may already be answered by someone else, but I knew the answer to this one so I wanted to jump in and contribute where I could.

On Friday, January 23, 2015 at 4:42:31 PM UTC-6, Zipette wrote:
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/47e5cc1f-cc64-476f-8ab8-daa9179b3a6a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to compare a var to 0 ?

Darrell Nicholas
No problem. Glad to be of help. I just learned that very thing a few days ago.

On Saturday, January 24, 2015 at 5:39:25 PM UTC-6, Zipette wrote:
Thanks a lot Darrell ! It was the problem ! I didn't let a the right spaces between terms, so you are completly true, the right formule is :

var a:Int = 5
if a != 0 {
println("Hello world")
}

As you notice, a space between "a" and "!=" and also a space between "=" and "0"

Thanks again for the time you spent on my question and also thanks to other one for their answers !
By



Le dimanche 25 janvier 2015 00:19:26 UTC+1, Darrell Nicholas a écrit :
Another thing, other than Int being spelled as INt and println having a capital P, you also have to have equal spaces on either side of your operator "!=". Either (a != 0) but you don't even need the parenthesis in this instance. 

var a:Int = 5
if a != 0 {
println("Hello world")
}

Hope that helps you. In a lot of cases you can have equal spaces or equal no spaces on either side of your operand, I think maybe on in assignments. a=5 or a = 5, but I
a= 5 or a =5 is wrong and will give an error. This is due to Swift's ability to do operator overloading. You could create an operator called a= that does something you define. The compiler looks at those spaces or lack or spaces due to this reason.

I am by no means a Swift expert, I've only been using it since June of last year ;-)

No really I just do this stuff as a hobby and this answer may already be answered by someone else, but I knew the answer to this one so I wanted to jump in and contribute where I could.

On Friday, January 23, 2015 at 4:42:31 PM UTC-6, Zipette wrote:
Hello,
Why the code bellow doe not compile...
var a:INt=5
if(a !=0)
{
     Println("Hello word")
}

The compilator does't accept this code, hox can copare the var "a" to 0 ?

Thanks.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/e0eedc82-c186-4a1a-8176-c05b069b2106%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.