When you use for network in networkid you don't need a break to stop the loop. It'll stop automatically when it has iterated over all items. If you want to exclude certain ID's from the script, either remove them on beforehand or skip them with an if statement like @Nash mentioned in her post. It's rare that break and continue's are "good programming practice". I'd also recommend that you make it easier on yourself by naming your variables more meaningfully. For example I'd change the name of the list to networkids and use networkid for the items in it. It'll make your code more readable/understandeable. Now for your code, it should be something like: for networkid in networkids:
success = 0
failure = 0
try:
result = meraki.addvlan(apikey, networkid, vlanid, name, subnet, mxip, surpressprint=False)
# skip the following networks
if networkid not in ['L_1648946644']:
# try to create the VLAN
if 200 <= int(result[0:3]) < 300: # check the returned status code
success += 1
print("VLAN created for ", networkid)
else:
failure += 1
print("Something went wrong while creating VLAN for ", networkid, " returned message was: ", result)
except ValueError as e:
print("Exception occured while trying to create VLAN for ", networkid, " invalid VLAN ID")
print('VLAN Addition Complete. Networks successful: ', success, ' Networks failed: ', failure)
... View more