Stick Online Forums

General => Off Topic => Topic started by: ARTgames on September 24, 2009, 06:10:46 PM

Title: if statement
Post by: ARTgames on September 24, 2009, 06:10:46 PM
In most programing languages is "any number">0=true and "any number"<1=false when using only whole numbers in a if statement?
Title: Re: if statement
Post by: Lingus on September 24, 2009, 06:55:19 PM
When using positive whole numbers, yes. If you include negative whole numbers then no, it is not always the case.
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 07:45:17 PM
Quote from: Lingus on September 24, 2009, 06:55:19 PM
When using positive whole numbers, yes. If you include negative whole numbers then no, it is not always the case.

So if im using negative number's than my statement
Quote"any number">0=true and "any number"<1=false
is not true.

Than what are they considered?(negative number's) true/false or n/a? For what languages have you tested this on?

Just to make sure we bother understand, i was implying that 0 and the numbers less than zero are considered false in my statement.

and yes i was include negative whole numbers.
Title: Re: if statement
Post by: Lingus on September 24, 2009, 08:14:58 PM
Quote from: ARTgames on September 24, 2009, 07:45:17 PM
Quote from: Lingus on September 24, 2009, 06:55:19 PM
When using positive whole numbers, yes. If you include negative whole numbers then no, it is not always the case.

So if im using negative number's than my statement
Quote"any number">0=true and "any number"<1=false
is not true.
Right.

Just as an example, replace "any number" with -1:

-1 > 0 = false (not true as in your statement) and -1 < 1 = true (not false as in your statement)

Not sure what you mean by, "What are they considered?" They're considered negative numbers... Do you mean your statements? They would be considered incorrect? I dunno...

I didn't test this with any languages, it's just logic. You can clearly see that when using any negative whole number in place of "any number" your statements are not correct.

Maybe if you put this in context... are you using this for something specific or was this just a generic question?
Title: Re: if statement
Post by: Mr Pwnage on September 24, 2009, 08:31:07 PM
Ususally...it is just:

1=true
0=false

2 wouldn't mean anything, so its not any number greater than one. You only really need one number to mean true anyways...if your going into more complex true/false...you can look into Boolean commands. Though I am not entirely sure what your after here cause I have a hard time reading your posts...I can probably be more help if your clearer.
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 08:53:26 PM
Aw yes, ill explain more. What i was placing out is that im asking what other commonly used languages would do in there if statement if something other than 1 and 0 were being used.

In GML when using whole numbers anything grader than one is true and anything less then it is false.

"If ( -1 )" in GML will consider it false. "If (100)" will be considered true in GML. I know i just tried it.

Now if i do "if -1" on my ti 83 it will return an error. If i do any value more than 1 it will also be true and 0 is always false.

So im asking if any one here knows how the if statement will acts in other languages with this.
(a simple way to test this would be to do a simple  "if (2) and if (-1)" and see what happens.)  

I have been asking around and what i heard about java was that it would also not work with negative whole numbers.

Why im asking this is when im making something and i what to quickly port (or just quickly make) it to another language i would like to know if i can use this as a quick and dirty trick to make it fast/easy(for me) and get the idea down like a drawing sketch. and lator ill fix it up. But really dont mind about the reasons why. i find ways to use things i never thought would work. i just like knowing i have that as an option.

Just building a referents in other words.
Title: Re: if statement
Post by: Lingus on September 24, 2009, 08:54:38 PM
Oh wow. Thank you Mr Pwnage. I completely misunderstood the question.

I see what Art is talking about now.

It entirely depends on the programming language. Some languages actually use the string "True" or "False". Sometimes -1 will be false and 0 will be true. It is completely arbitrary. Check out the help/documentation for the language in question. If you are using a specific language let us know. Maybe someone knows what that language uses for true and false.

Edit: I see, so you're just curious about other common languages. To be honest, I'm not certain on any specifics. I would look up data types in each of the languages you would use and look for the boolean data type. It should state what the parameters are.

Here's the wiki article on it: http://en.wikipedia.org/wiki/Boolean_data_type
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 09:01:35 PM
this post has been edited because lings edit with his new answer.

2d edit: i looked at that wiki and it not help at first glance. i will come back later.
Title: Re: if statement
Post by: JoEL on September 24, 2009, 09:17:14 PM
-1 usually doesn't mean false, it usually means an error occurred.

If statement already checks if the statement is true, returning a 0 or 1. From what I understand all languages use the same logic when it comes to this.

But you can't use an if statement for something like
if(-2) or if(2) because an if statement has to be comparing something...like
if(-2 < 2)
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 09:26:25 PM
Your understand of my post was little. not blaming you im a bad writer. Im not saying i got a return of "-1".

Im saying I used -1 in GML and it treated it like a false. and on my ti 83 it did not even work (using -1).

And yes i know the if statement checks if its true. But im not asking that. Im asking what does the if statement in other languages consider true and false other than 1 and 0 if they even do so at all. and i have came across 2 instances ware the if statement treats other whole numbers in this way.
Title: Re: if statement
Post by: JoEL on September 24, 2009, 09:33:16 PM
Well re-read what I said above

Quote
But you can't use an if statement for something like
if(-2) or if(2) because an if statement has to be comparing something...like
if(-2 < 2)

All languages only consider 1 and 0 as false or true.
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 09:44:41 PM
Quote from: JoEL on September 24, 2009, 09:33:16 PM
But you can't use an if statement for something like

not necessarily. In GML for example.  


if ( 2 ){

   show_message( "if (2) is true")  //this should pop up
}

if ( -1 ){

   show_message( "If you see this -1 is true") //this should not pop up

}

if ( 5 + 5 ){
   
   show_message( " if you see this gm used 10 as true") //this should pop up
}

if ( 5 - 6 ){
   
   show_message( " if you see -1 is true") //this should not pop up
}


test for ones self.

edit: Im asking what other languages (that some one know of) exhibit this behavior. so i can exploit it for my own reasons.
Title: Re: if statement
Post by: JoEL on September 24, 2009, 10:09:41 PM
oh, it'd be checking if it's a positive number. true being positive false being negative. I don't know why you are asking if 2 is a positive number though, I've got no understanding on what you are trying to accomplish...

Quote
not necessarily. In GML for example

I take it back, you can, but theres no reason to do that...I don't understand the purpose.
Title: Re: if statement
Post by: ARTgames on September 24, 2009, 10:48:13 PM
Quote from: JoEL on September 24, 2009, 10:09:41 PM
I take it back, you can, but theres no reason to do that...I don't understand the purpose.

in my past post i said:

QuoteWhy im asking this is when im making something and i what to quickly port (or just quickly make) it to another language i would like to know if i can use this as a quick and dirty trick to make it fast/easy(for me) and get the idea down like a drawing sketch. and lator ill fix it up. But really dont mind about the reasons why. i find ways to use things i never thought would work. i just like knowing i have that as an option.

maybe this was not a good place to ask.
Title: Re: if statement
Post by: JoEL on September 24, 2009, 11:05:04 PM
btw, about the "java doesn't work with negetive numbers as well"

I don't think that's true, GM defenatly can work with negative numbers, if you ask for example:

if ( -20 < -10)
{
show_message('-20 is lower then -10')
}

now that's working with negative numbers, I'm not 100% if that works like that, you may have to set the negative's as variables...
Title: Re: if statement
Post by: Mr Pwnage on September 24, 2009, 11:24:09 PM
Well Art what point are you trying to get at? What is the point of having more than one number represent true/false? I guess I don't see what you getting at. Regardless, if you are trying to learn more about if statements, look up: the "Boolean" data structure. It is pretty much a way to represent comparisons of data and than display them as a true or false output. If you have something else that needs being answered, please take some time to spell check it and make it legible so we can understand where your getting at with this topic, as I have no idea what your trying to understand, thanks.
Title: Re: if statement
Post by: Lingus on September 25, 2009, 04:00:47 PM
If you look back at the wiki article and review it more thoroughly it will give you the answer to your question. Specifically, go under the section titled "Boolean types and operations in modern languages" and find the language you are looking for. It will have a little bit about Boolean types in that language and how it works. For instance under C++:
QuoteValues of type bool are either true or false.[5] Implicit conversions exist between bool and other integral types, floating point types, pointer types, and pointer-to-member types.[6] In addition, user-defined types can be converted to bool via a user-defined conversion operator. In general, a zero or null-pointer value is converted to false, any other value is converted to true.
And btw, Joel, this actually proves you wrong. The reason why -1 works as true (I know I said false) in this case is because it is a non-zero value. So you could use any number besides zero and it would convert to true.
Title: Re: if statement
Post by: ARTgames on September 25, 2009, 05:18:12 PM
Quote from: JoEL on September 24, 2009, 11:05:04 PM
btw, about the "java doesn't work with negetive numbers as well"

I don't think that's true, GM defenatly can work with negative numbers, if you ask for example:

if ( -20 < -10)
{
show_message('-20 is lower then -10')
}

now that's working with negative numbers, I'm not 100% if that works like that, you may have to set the negative's as variables...

>_< no! if (-1) in java not if (-1<-2)....

@Mr Pwnage  read http://www.stick-online.com/boards/index.php?topic=337.msg5783#msg5783 You seem to be the only one having problems with my writing in this topic also. im not saying its good (my writing) but other people seem to understand it well. :/

@Lingus mmmk. as i said i did not look threw it well. But the quote you pulled out was wast i was looking for. Thank you
Title: Re: if statement
Post by: Lingus on September 25, 2009, 08:22:09 PM
Quote from: ARTgames on September 25, 2009, 05:18:12 PM
@Mr Pwnage  read http://www.stick-online.com/boards/index.php?topic=337.msg5783#msg5783 You seem to be the only one having problems with my writing in this topic also. im not saying its good (my writing) but other people seem to understand it well. :/

@Lingus mmmk. as i said i did not look threw it well. But the quote you pulled out was wast i was looking for. Thank you
Yea, that was just one of the languages on that page. There's around 20 or so.

As far as understanding your writing, it's not that you need to spell check like Pwnage said. It wouldn't hurt, but spelling/grammar is not the reason why someone might misunderstand you. So his advice was misplaced. What I have trouble sometimes is in the logic of your statements. I will assume you are talking about one thing because of your phrasing, but you were actually talking about something else. It took me a post or two to realize what you were talking about here... But after that I get it. No big deal.
Title: Re: if statement
Post by: ARTgames on September 25, 2009, 08:38:14 PM
Quote from: Lingus on September 25, 2009, 08:22:09 PM
As far as understanding your writing, it's not that you need to spell check like Pwnage said. It wouldn't hurt, but spelling/grammar is not the reason why someone might misunderstand you. So his advice was misplaced. What I have trouble sometimes is in the logic of your statements. I will assume you are talking about one thing because of your phrasing, but you were actually talking about something else. It took me a post or two to realize what you were talking about here... But after that I get it. No big deal.

I agree with that. But in my posts i do try to make them readable. any way in most of posts you will see the "edit" in the bottom in the small found. im not a good writer at all.
Title: Re: if statement
Post by: JoEL on September 26, 2009, 05:28:49 AM
Quote from: ARTgames on September 25, 2009, 05:18:12 PM
Quote from: JoEL on September 24, 2009, 11:05:04 PM
btw, about the "java doesn't work with negetive numbers as well"

I don't think that's true, GM defenatly can work with negative numbers, if you ask for example:

if ( -20 < -10)
{
show_message('-20 is lower then -10')
}

now that's working with negative numbers, I'm not 100% if that works like that, you may have to set the negative's as variables...

>_< no! if (-1) in java not if (-1<-2)....

You would never use if (-1) though....this seems like a ridiculous question now that I think about it...I don't see how this would fit into any program, why would you test if (-1) was true or false ?
Title: Re: if statement
Post by: ARTgames on September 26, 2009, 09:17:07 AM
I wouldn't. >_< I would use other stuff in conjunction with it and have the possibility of "-1" as a chance. I just simplified it to "-1" as the ending results the if statement hast to take care of. 

like "if ( abs( a - 1) )" can be used for a xor. And can be a helpful tick in vary simple languages or in a competition. or just simply to find new ways to do something to help find out ware a problem you might be having is in your program.

i explained this in my 3ed post in this topic. http://www.stick-online.com/boards/index.php?topic=337.msg5767#msg5767
Title: Re: if statement
Post by: JoEL on September 26, 2009, 11:47:26 AM
Yeah, but we come back to the problem where you aren't very good at explaining things...but at least in the end you got your answer. Congratulations, oh and I learnt something ;)
Title: Re: if statement
Post by: ARTgames on September 26, 2009, 12:45:20 PM
help me and tell me what part you dont understand. I need to work on this.
Title: Re: if statement
Post by: Lingus on September 26, 2009, 06:50:48 PM
Actually, if(x) is a valid test. You're checking whether x converts to true or false. If it's zero or null it will be false. If anything else it's true. So saying if(-1) is the same thing.
Title: Re: if statement
Post by: Mr Pwnage on September 26, 2009, 08:20:18 PM
So just for clarification...are you really just messing around with the syntax of various languages? Seeing if they can be written multiple ways? I am so lost right now.
Title: Re: if statement
Post by: ARTgames on September 26, 2009, 08:45:10 PM
Quote from: Lingus on September 26, 2009, 06:50:48 PM
Actually, if(x) is a valid test. You're checking whether x converts to true or false. If it's zero or null it will be false. If anything else it's true. So saying if(-1) is the same thing.

what? who were you talking to?

@Mr Pwnage
it really does not matter any more. ling and other people have helped me.
Title: Re: if statement
Post by: Lingus on September 28, 2009, 01:20:35 AM
Quote from: ARTgames on September 26, 2009, 08:45:10 PM
Quote from: Lingus on September 26, 2009, 06:50:48 PM
Actually, if(x) is a valid test. You're checking whether x converts to true or false. If it's zero or null it will be false. If anything else it's true. So saying if(-1) is the same thing.

what? who were you talking to?
Joel. It was in response to this:

Quote from: JoEL on September 26, 2009, 05:28:49 AM
You would never use if (-1) though....this seems like a ridiculous question now that I think about it...I don't see how this would fit into any program, why would you test if (-1) was true or false ?