0
FOR WHAT PURPOSE WE USE BOOLEAN???
?????????????????????
9 Answers
+ 5
Boolean is used in condition testing
+ 3
Do you know it? - false
Did you write in caps and wrote a lot of '?'? - true
+ 3
Basicly it is answering/asking "Yes/No"-Questions
+ 3
Boolean gives only 2 results -
True or False
Right or wrong
Yes or Not
+ 3
to keep it simple, a boolean is an on off switch.
Maybe your making Mario Bros. You can't jump if you aren't on the ground.
You push the A button...
if(onGround==True)
Jump
if(onGround==False)
No Jump
Your writing a simple while loop. Use a boolean to tell it when to stop.
run=True
while run==True:
loop until run=False
+ 2
ok thns
+ 1
This avoids you to use useless conditions. For example :
//without boolean
function test() {
return 0
}
if(test()==0){
//code here
}
//with boolean
function test() {
return true
}
if(test()) { //don't have to check an equality
//code here
}
and if you want to check if the function returns false you can just write : if(!test())
But this can also help you if the function has to return a number resulting of a calculation. If there is an invalid parameter, you can just return false to prevent of the error.
+ 1
@D B
I don't understand sorry
0
@Antoine Bergerault:
In your last sentence:
I want a number! What is... ?
Function: "False"
Do. Not. Return. Other. Datatypes.
If anybody thinks different, let me know.