Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCharel Grate
306 PointsOpen Brakcets
Why are there sometimes two opening brackets? I understand what the first open bracket does but the second open one confuses me for example....
do{
response = console.readLine( " Do you understand do while loops?"); isInvalid = response.equalsIgnoreCase("No"); if (isInvalid)
{
^ //im alittle consfused with this bracket :0
console.printf(" This is invalid......\n Please try again");
}
}while(isInvalid);
1 Answer
Lauren Moineau
9,483 PointsHi. The first opening curly bracket belongs to the do statement and the second opening curly bracket belongs to the if statement.
do { // Opening bracket of the do statement
response = console.readLine(" Do you understand do while loops?");
isInvalid = response.equalsIgnoreCase("No");
if (isInvalid) { // Opening bracket of the if statement
console.printf(" This is invalid......\n Please try again");
} // Closing bracket of the if statement
} while (isInvalid); // Closing bracket of the do statement
The if statement is inside the do statement. Think of it as Russian nesting dolls. That's why using proper indentation is vital here to read the code easily.
Hope that helps :).