Path: csiph.com!news.swapon.de!eternal-september.org!feeder.eternal-september.org!newsfeed1.swip.net!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed-00.mathworks.com!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: If one IF is satisfied, skip the rest in the nest... Date: Wed, 21 Oct 2015 17:46:38 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 50 Message-ID: References: <50a6789a-3965-430b-9a91-b08adcedf7bf@googlegroups.com> NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1445449598 23300 166.84.1.1 (21 Oct 2015 17:46:38 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Wed, 21 Oct 2015 17:46:38 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:97866 In <50a6789a-3965-430b-9a91-b08adcedf7bf@googlegroups.com> bigred04bd3@gmail.com writes: > So here what I have, I have a 3 IF's within the same level. If one IF is s= > atisfied, I would like to "skip" the other IFs and continue with my code. > # 4 second open > if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 and wb1_sheet1.cell(row=cell + 1, column=3).value == 0 and wb1_sheet1.cell(row=cell + 2, column=2).value == 0 and wb1_sheet1.cell(row=cell + 2, column=3).value == 0 and wb1_sheet1.cell(row=cell + 3, column=2).value == 0 and wb1_sheet1.cell(row=cell + 3, column=3).value == 0: > open += 3 > open_seconds += 4 > start = wb1_sheet1.cell(row=cell + 4, column=2).coord= > inate > break > # 3 second open > if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 a= > nd wb1_sheet1.cell(row=cell + 1, column=3).value == 0 and wb1_sheet= > 1.cell(row=cell + 2, column=2).value == 0 and wb1_sheet1.cell(row= > =cell + 2, column=3).value == 0: > open += 3 > start = wb1_sheet1.cell(row=cell + 3, column=2).coord= > inate > open_seconds += 3 > continue > # 2 second open > if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 a= > nd wb1_sheet1 .cell(row=cell + 1, column=3).value == = > 0: > open += 3 > start = wb1_sheet1.cell(row=cell + 2, column=2).coord= > inate > open_seconds += 2 > if any but the last IF is true, then all IFs will be true...that's my probl= > em. It looks like all three of your if statements start out with this condition: if wb1_sheet1.cell(row=cell + 1, column=2).value == 0 and wb1_sheet1.cell(row=cell + 1, column=3).value == 0 So you could reorganize your code by putting an if statement at the top that only checks this condition. Then, indented underneath, you can check for the other conditions. And be sure to use "else" and "elif" when they are appropriate. -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"