News:

FOR INFORMATION ON DONATIONS, AND HOW TO OBTAIN ACCESS TO THE GAME, PLEASE VIEW THE FOLLOWING TOPIC: http://stick-online.com/boards/index.php?topic=2.0

Main Menu

if statement

Started by ARTgames, September 24, 2009, 06:10:46 PM

Previous topic - Next topic

ARTgames

In most programing languages is "any number">0=true and "any number"<1=false when using only whole numbers in a if statement?

Lingus

When using positive whole numbers, yes. If you include negative whole numbers then no, it is not always the case.

ARTgames

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.

Lingus

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?

Mr Pwnage

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.
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." -Albert Einstein (1947)

http://www.benmward.com/projects.php

ARTgames

#5
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.

Lingus

#6
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

ARTgames

#7
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.

JoEL

#8
-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)

ARTgames

#9
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.

JoEL

#10
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.

ARTgames

#11
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.

JoEL

#12
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.

ARTgames

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.

JoEL

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...