leaving an if statement (should be easy)

V

vamp4l

wandering if there is a way to leave a nested if statement to test the
next if statement

for example

if (i >= 6){
if (i >= 12)
cout << ">12\n"
else (what would i need to put here to leave this if-else block to
continue on to test the next condition?)
}
if (i >= 4){
if (i >= 6)
....
}
 
H

Howard

vamp4l said:
wandering if there is a way to leave a nested if statement to test the
next if statement

for example

if (i >= 6){
if (i >= 12)
cout << ">12\n"
else (what would i need to put here to leave this if-else block to
continue on to test the next condition?)

Nothing. Just drop the word "else" (and add a semicolon to the line above,
which needs one in either case).
 
A

akarl

vamp4l said:
wandering if there is a way to leave a nested if statement to test the
next if statement

for example

if (i >= 6){
if (i >= 12)
cout << ">12\n"
else (what would i need to put here to leave this if-else block to
continue on to test the next condition?)
}
if (i >= 4){
if (i >= 6)
....
}

if (i >= 12) { cout << ">12\n"; }

Generally

if (p) {
if (q) {
s;
}
}

should be written as

if (p && q) { s; }


August
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top