Results 1 to 6 of 6
- 11-15-2012, 04:40 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 15
- Rep Power
- 0
condition
hi
please help me understand this piece of code
Java Code:boolean condition = false; while (!condition){ //do something } if(!condition){ // do something }
I also have some statements which are familiar for me like
if (something == true)
or while (something == true)
but actually I don't understand the previous piece of code
which is equal to "!condition" ??
I know it means while (true) but does this mean that the loop won't terminate ?
and what about if(true)? which is equal to true ?
- 11-15-2012, 06:11 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: condition
The loop will only not terminate if there is no code in the loop to terminate it.
This could be a 'break;' command or some code changing the value of 'condition' to 'true'.
What happens with the if statement is entirely dependent on how the loop exited.Please do not ask for code as refusal often offends.
** This space for rent **
- 11-15-2012, 07:14 PM #3
Member
- Join Date
- Sep 2012
- Posts
- 15
- Rep Power
- 0
Re: condition
what if you considered them as separate pieces? I mean what if the if statement was dependant (no loops before it).
- 11-15-2012, 07:24 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: condition
Then the if condition would be utterly pointless as it would always be true.
Please do not ask for code as refusal often offends.
** This space for rent **
- 11-15-2012, 07:31 PM #5
Member
- Join Date
- Sep 2012
- Posts
- 15
- Rep Power
- 0
Re: condition
so if !condition becomes false this should breaks out of the code and it wouldn't execute the if's body, right ?
- 11-15-2012, 08:25 PM #6
Similar Threads
-
Why twice condition check?
By megabull in forum New To JavaReplies: 4Last Post: 09-11-2012, 07:14 PM -
Condition ignored.
By Pojahn_M in forum New To JavaReplies: 8Last Post: 12-09-2011, 03:21 AM -
Waiting on a condition
By nephos in forum New To JavaReplies: 9Last Post: 04-22-2011, 11:05 AM -
basic condition
By ts96 in forum New To JavaReplies: 1Last Post: 02-16-2011, 01:23 PM -
While loop condition
By counterfox in forum New To JavaReplies: 3Last Post: 10-10-2010, 02:14 AM
Bookmarks