What's the meaning of (boolean isComplete = true;" for me this line is useless


#1



Replace this line with your code.


#2

It in fact is not how you put it 'useless' because what you are doing is storing the boolean true in the variable isComplete.


#3

i mean, it's to simple, easy. I'm beginner but I don'T UNDERSTAND WHAT i'M DOING WITH THIS LINE OF CODE.


#4

You're doing exactly what I said you create a variable named isComplete and store the boolean true in that variable.


#5

You might for example want to test if there is an 'a' in a string, you'd start with saying that, no, there isn't one (false) and then loop through the string, changing the boolean to true upon finding an 'a' (and exiting the loop since there's no reason to continue once an 'a' has been found)


#6

@sbernaldez

The line boolean isComplete = true; sets a boolean value to true.

You seem to be having trouble with the idea of a boolean. To fix this, imagine a simple on/off lightswitch. If that lightswitch controlled a boolean statement, let's call it lightswitchstatus, then if it was in the on condition, it would be considered true. If it is in the off condition, it would be considered false. So if the value of lightswitchstatus is true, then the light is on. If it is false, then the light is off.

Now that you have a basic understanding of boolean values, let's look at your line.

boolean isComplete = true;

Let's break down the statement.

boolean is declaring what type of variable this is. This tells us it is a boolean, or our "lightswitch" variable. It can either be on or off, true or false.

isComplete is the variable name. As with your name, it tells you what that value should be called. In your case, the "value" is you. When someone calls your name, you respond. Similarly, when someone calls our variable by its name, it knows to use that value in whatever you are telling it to do.

= is how you declare the variable. The variable name is equal to the value of the variable, so if I said integer two = 2; the variable two would be set to two.

; is the execution. You need this on all statements in Java. This shows the end of a statement. If you don't have this, your code will error.

So in plain English, your statement tells your program the following:

There is a boolean value called isComplete that is set to the value true. (On Lightswitch)

I hope this helped you learn boolean variables, and with your question. If you need more help, I'd be happy to help, just tag me. Good luck. :slight_smile:


#7

this was a very helpful response